我正在将序列化的 nsdictionary 存储并加载到钥匙串中,如本文(将NSDictionary 存储在钥匙串中),但我需要能够更新/编辑字典内容,所以我想删除它并重新添加。
我只是不知道该怎么做。我从上面的帖子中获取了以下代码:
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"arbitraryId" accessGroup:nil]
NSString *error;
//The following NSData object may be stored in the Keychain
NSData *dictionaryRep = [NSPropertyListSerialization dataFromPropertyList:dictionary format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
[keychain setObject:dictionaryRep forKey:kSecAttrService];
//When the NSData object object is retrieved from the Keychain, you convert it back to NSDictionary type
dictionaryRep = [keychain objectForKey:kSecAttrServce];
NSDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:dictionaryRep mutabilityOption:NSPropertyListImmutable format:nil errorDescription:&error];
SecItemDelete((CFDictionaryRef)dictionaryRep); // doesnt work
这些值不会从钥匙串中删除。
谢谢