2

我正在使用 keychain 类在 keychain 中存储一些值。通过使用这些钥匙串默认方法

KeychainItemWrapper *item = [[KeychainItemWrapper alloc] initWithIdentifier:@"identifier" accessGroup:nil];

 [item setObject:@"some_value" forKey:(id)kSecAttrService];
[item setObject:@"Some_value" forKey:(id)kSecValueData];

当我关闭应用程序并再次启动它并初始化钥匙串对象时,值已成功保存在钥匙串中

then this  condition in this function of keychain

- (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup`

是真的,因为我的密钥被重置并且没有返回值

    if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr)
    {
        // Stick these default values into keychain item if nothing found.
        [self resetKeychainItem];

        // Add the generic attribute and the keychain access group.
        [keychainItemData setObject:identifier forKey:(id)kSecAttrGeneric];
        if (accessGroup != nil)
        {

            // Ignore the access group if running on the iPhone simulator.
            // 
            // Apps that are built for the simulator aren't signed, so there's no keychain access group
            // for the simulator to check. This means that all apps can see all keychain items when run
            // on the simulator.
            //
            // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the
            // simulator will return -25243 (errSecNoAccessForItem).

            [keychainItemData setObject:accessGroup forKey:(id)kSecAttrAccessGroup];

        }
    }

原因是这些方法返回 nil

[item objectForKey:(id)kSecAttrService];
[item objectForKey:(id)kSecValueData];

我不明白,当第一次保存价值时,为什么这种情况为真。

有谁能够帮我

谢谢

4

0 回答 0