Ser*_*nce 6 iphone cocoa-touch keychain ios
我有以下代码在钥匙串中创建钥匙串项目:
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[dict setObject: (__bridge id) kSecClassGenericPassword forKey: (__bridge id) kSecClass];
[dict setObject: MYKEY forKey: (__bridge id) kSecAttrService];
[dict setObject: @"0" forKey: (__bridge id) kSecValueData];
SecItemAdd ((__bridge CFDictionaryRef) dict, NULL);
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.如果我想更改此项,是否有人可以为SecItemUpdate提供准确的语法?
更新:具有以下内容:
NSMutableDictionary *query = [NSMutableDictionary dictionary];
NSMutableDictionary *attributesToUpdate = [NSMutableDictionary dictionary];
[query setObject: (__bridge id) kSecClassGenericPassword forKey: (__bridge id) kSecClass];
[query setObject: MYKEY forKey: (__bridge id) kSecAttrService];
[query setObject: (id) kCFBooleanTrue forKey: (__bridge id) kSecReturnData];
NSString *numberOfBalloonsString = [NSString stringWithFormat:@"%d", numberOfBalloonsUsed];
NSData *numberOfBalloonsData = [numberOfBalloonsString dataUsingEncoding:NSUTF8StringEncoding];
[attributesToUpdate setObject: numberOfBalloonsData forKey:(__bridge id)kSecValueData];
OSStatus error = SecItemUpdate ((__bridge CFDictionaryRef) query, (__bridge CFDictionaryRef) attributesToUpdate);
NSLog(@"Error #: %ld", error);
Run Code Online (Sandbox Code Playgroud)
我收到错误代码-50 =
传递给函数的一个或多个参数无效.
SecItemUpdate 非常有文件证明.
该query参数SecItemUpdate是记录作为查询(如在其他功能中使用),以及在模糊的说法:"指定其数值需更改的项目".这似乎意味着您必须在此字典中包含您想要更改的现有属性值,但我认为您不会这样做.我发现你可以使用query你用来获取你想要更新的项目的属性.
该attributes参数应该是添加SecItemCopyMatching了kSecValueData键和值以及更改了任何属性的结果.