Ios 钥匙链可以’;找不到项目,但可以’;不创建项目
iOS上的钥匙链真的有问题 下面是self.keychainItemQuery: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
{
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=;
}