简体   繁体   中英

NSInternalInconsistencyException when keychain item update

i'm use keychain in my app with keychainitemwrapper. So, i did update 'kSecAttrAccessible' use setObject:(id) method.
But errors occur. Like this,

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't update the Keychain Item.'

and this is my source

KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"UserData" accessGroup:@"49YVVGB32W.com.covimdm.daelim.pushData"];
NSString *PushData = [NSString stringWithFormat:@"%@::%@::%@", sLoginId, [[[PushManager defaultManager] info] pushServiceID], [[[PushManager defaultManager] info] host]];
[wrapper setObject:PushData forKey:(id)kSecValueData];
[wrapper setObject:(id)kSecAttrAccessibleAfterFirstUnlock forKey:(id)kSecAttrAccessible];

The part where the error occurs is the fourth line code.

[wrapper setObject:(id)kSecAttrAccessibleAfterFirstUnlock forKey:(id)kSecAttrAccessible];

i don't know why error occurs on and over again.

EDIT

Ok, let us try again. The wrapper library you use is specifically for a single object it seems, so it seems to crash when you add the keychain attributes. However, it seems to work if you do it first. So first load the configuration and then the item data as below and it should work.

    KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"UserData"
                                       accessGroup:@"49YVVGB32W.com.covimdm.daelim.pushData"];

    NSString * pushString = @"Some string";
    NSData   * pushData   = [pushString dataUsingEncoding:NSUTF8StringEncoding];

    [wrapper setObject:kSecAttrAccessibleAfterFirstUnlock
            forKey:kSecAttrAccessible]; // Do configuration first
    [wrapper setObject:pushString // Must be string!?
            forKey:kSecValueData];

The code above is working on this side, albeit with KeychainItemWrapper from here . From the source it seems the item is written each time you set an object, so therefore I think you need the configuration first.

Also, it did NOT work if I stored data as I suggested earlier. It seems you have to store the string. The code above worked fine this side, hope it does the same for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM