iOS Keychain Services: only specific values allowed for kSecAttrGeneric Key?

前端 未结 3 1401
夕颜
夕颜 2020-12-04 08:36

I am trying to use the KeychainWrapper class provided in this Apple sample code: https://developer.apple.com/library/content/samplecode/GenericKeychain/

In the sampl

3条回答
  •  春和景丽
    2020-12-04 09:04

    Simon almost fixed my issue because after changing the KeychainItemWrapper.m, I had issues getting and setting data to and from the keychain. So after adding this to the KeychainItemWrapper.m, I used this to get and store items:

    KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithAccount:@"Identfier" service:@"AppName" accessGroup:nil];
    [keychainItem setObject:@"some value" forKey:(__bridge id)kSecAttrGeneric];
    NSString *value = [keychainItem objectForKey: (__bridge id)kSecAttrGeneric];
    

    Because [keychainItem objectForKey: (__bridge id)kSecAttrService] is returning the Account (in this example @"Identifier") which makes sense but it took me some time before I realized I needed to use kSecAttrGeneric to fetch data from the wrapper.

提交回复
热议问题