首页 » 移动 » iOS使用keychain的SecItemAdd返回-50的问题

iOS使用keychain的SecItemAdd返回-50的问题

 

很简单的一段代码如下

+ (NSMutableDictionary *)getKeychainQuery:(NSString *)service {

return [NSMutableDictionary dictionaryWithObjectsAndKeys:

(id)kSecClassGenericPassword, (id)kSecClass,

service, (id)kSecAttrServer,

service, (id)kSecAttrAccount,

(id)kSecAttrAccessibleAfterFirstUnlock, (id)kSecAttrAccessible,

nil];

}

相信很多同学在搜索获取唯一UUID的时候都会找到这段代码,看上去也没有任何问题,但是我在实际使用中SecItemAdd一直返回-50,也就是参数错误,百度谷歌都没有找到问题答案,于是我一怒之下从删参数开始测,当我注释掉service, (id)kSecAttrServer,这一行的时候奇迹出现了。SecItemAdd居然没报错,而且真机模拟器上面都跑过了,UUID是唯一的,删掉之后再安装也还是不变。这是为什么呢?

测试环境是:xcode 7.3   iOS9.3  iOS7.0

Apple给的说明https://developer.apple.com/reference/security/ksecattrserver?language=objc

The corresponding value is of type CFStringRef and contains the server's domain name or IP address. Items of class kSecClassInternetPassword have this attribute.

可是我仍然不知道是什么原因造成的。希望广大网友们有碰到这个问题的时候可以帮我解释一下,谢谢。

原文链接:iOS使用keychain的SecItemAdd返回-50的问题,转载请注明来源!