Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 钥匙链可以’;找不到项目,但可以’;不创建项目_Ios_Objective C_Keychain - Fatal编程技术网

Ios 钥匙链可以’;找不到项目,但可以’;不创建项目

Ios 钥匙链可以’;找不到项目,但可以’;不创建项目,ios,objective-c,keychain,Ios,Objective C,Keychain,iOS上的钥匙链真的有问题 下面是self.keychainItemQuery: { kSecClass = kSecClassGenericPassword; kSecAttrGeneric = "com.mycompany.player"; kSecMatchLimit = kSecMatchLimitOne; kSecReturnAttributes = kCFBooleanTrue; } 当我这样做的时候 OSStatus status = SecIte

iOS上的钥匙链真的有问题

下面是self.keychainItemQuery:

{
    kSecClass = kSecClassGenericPassword;
    kSecAttrGeneric = "com.mycompany.player";
    kSecMatchLimit = kSecMatchLimitOne;
    kSecReturnAttributes = kCFBooleanTrue;
}
当我这样做的时候

OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)self.keychainItemQuery, &attributes);
我明白了

status == errSecItemNotFound
好的,这里是self.keychainItemData:

{
    kSecAttrAccount = "";
    kSecClass = kSecClassGenericPassword;
    kSecAttrDescription = "";
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrLabel = "";
    kSecValueData = <35663636 65623135 64303139 65363535>;
}
我明白了

我以为钥匙链上的物品被锁死了
kSecAttrGeneric
。上面的查询在代码中的其他点查找keychain项。我觉得我遗漏了一些关于为什么这不起作用的细节。

这是关于你的问题的

简而言之,您还需要为键
kSecAttrAccount
kSecAttrService
设置值
kSecClassGenericPassword
显然是根据这两个值确定钥匙链条目的唯一性

您可以在
kSecAttrService
中重用
kSecAttrGeneric
的值,但每个钥匙链条目都需要一个唯一的
kSecAttrAccount

更新示例时,
self.keychainItemQuery
将变为:

{
    kSecClass = kSecClassGenericPassword;
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrAccount = "account";               // This value should be unique for each entry you add
    kSecAttrService = "com.mycompany.player";
    kSecMatchLimit = kSecMatchLimitOne;
    kSecReturnAttributes = kCFBooleanTrue;
}
{
    kSecAttrAccount = "";
    kSecClass = kSecClassGenericPassword;
    kSecAttrDescription = "";
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrAccount = "account";               // This value should be unique for each entry you add
    kSecAttrService = "com.mycompany.player";
    kSecAttrLabel = "";
    kSecValueData = <35663636 65623135 64303139 65363535>;
}
self.keychainItemData
变成:

{
    kSecClass = kSecClassGenericPassword;
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrAccount = "account";               // This value should be unique for each entry you add
    kSecAttrService = "com.mycompany.player";
    kSecMatchLimit = kSecMatchLimitOne;
    kSecReturnAttributes = kCFBooleanTrue;
}
{
    kSecAttrAccount = "";
    kSecClass = kSecClassGenericPassword;
    kSecAttrDescription = "";
    kSecAttrGeneric = "com.mycompany.player";
    kSecAttrAccount = "account";               // This value should be unique for each entry you add
    kSecAttrService = "com.mycompany.player";
    kSecAttrLabel = "";
    kSecValueData = <35663636 65623135 64303139 65363535>;
}
{
kSecAttrAccount=“”;
kSecClass=kSecClassGenericPassword;
kSecAttrDescription=“”;
kSecAttrGeneric=“com.mycompany.player”;
kSecAttrAccount=“account”//此值对于您添加的每个条目都应该是唯一的
kSecAttrService=“com.mycompany.player”;
kSecAttrLabel=“”;
kSecValueData=;
}