i using keychainitemwrapper class saving data in keychain, app crashing crash log terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'couldn't add keychain item.'
here method write data in keychain
- (void)writetokeychain { nsdictionary *attributes = null; nsmutabledictionary *updateitem = null; osstatus result; if (secitemcopymatching((cfdictionaryref)genericpasswordquery, (cftyperef *)&attributes) == noerr) { // first need attributes keychain. updateitem = [nsmutabledictionary dictionarywithdictionary:attributes]; // second need add appropriate search key/values. [updateitem setobject:[genericpasswordquery objectforkey:(id)ksecclass] forkey:(id)ksecclass]; // lastly, need set updated attribute list being careful remove class. nsmutabledictionary *tempcheck = [self dictionarytosecitemformat:keychainitemdata]; [tempcheck removeobjectforkey:(id)ksecclass]; #if target_iphone_simulator // remove access group if running on iphone simulator. // // apps built simulator aren't signed, there's no keychain access group // simulator check. means apps can see keychain items when run // on simulator. // // if secitem contains access group attribute, secitemadd , secitemupdate on // simulator return -25243 (errsecnoaccessforitem). // // access group attribute included in items returned secitemcopymatching, // why need remove before updating item. [tempcheck removeobjectforkey:(id)ksecattraccessgroup]; #endif // implicit assumption can update single item @ time. result = secitemupdate((cfdictionaryref)updateitem, (cfdictionaryref)tempcheck); nsassert( result == noerr, @"couldn't update keychain item." ); } else { // no previous item found; add new one. result = secitemadd((cfdictionaryref)[self dictionarytosecitemformat:keychainitemdata], null); nsassert( result == noerr, @"couldn't add keychain item." ); } }
my app crashing at
result = secitemadd((cfdictionaryref)[self dictionarytosecitemformat:keychainitemdata], null);
with assertion error message assertion failure in -[keychainitemwrapper writetokeychain]
here values assigned in keychainitemdata
printing description of self->keychainitemdata: { acct = ""; desc = ""; gena = "com.xyz.abc"; labl = ""; "v_data" = "abcdss-abcdss-abcdss-test-data"; }
i know similar questions has been asked here many time nothing me.
can me out ? there other approach save data in keychain.
thanks in advance.
using self.keychainitemdata instead of keychainitemdata in method ?
- (void)writetokeychain { nsdictionary *attributes = null; nsmutabledictionary *updateitem = null; osstatus result; if (secitemcopymatching((cfdictionaryref)genericpasswordquery, (cftyperef *)&attributes) == noerr) { // first need attributes keychain. updateitem = [nsmutabledictionary dictionarywithdictionary:attributes]; // second need add appropriate search key/values. [updateitem setobject:[genericpasswordquery objectforkey:(id)ksecclass] forkey:(id)ksecclass]; // lastly, need set updated attribute list being careful remove class. nsmutabledictionary *tempcheck = [self dictionarytosecitemformat:self.keychainitemdata]; [tempcheck removeobjectforkey:(id)ksecclass]; #if target_iphone_simulator // remove access group if running on iphone simulator. // // apps built simulator aren't signed, there's no keychain access group // simulator check. means apps can see keychain items when run // on simulator. // // if secitem contains access group attribute, secitemadd , secitemupdate on // simulator return -25243 (errsecnoaccessforitem). // // access group attribute included in items returned secitemcopymatching, // why need remove before updating item. [tempcheck removeobjectforkey:(id)ksecattraccessgroup]; #endif // implicit assumption can update single item @ time. result = secitemupdate((cfdictionaryref)updateitem, (cfdictionaryref)tempcheck); nsassert( result == noerr, @"couldn't update keychain item." ); } else { // no previous item found; add new one. result = secitemadd((cfdictionaryref)[self dictionarytosecitemformat:self.keychainitemdata], null); nsassert( result == noerr, @"couldn't add keychain item." ); } }
Comments
Post a Comment