尝试在安全链中添加项目时,请继续获取-50. var query = [String:AnyObject]() query[kSecClass as String] = kSecClassGenericPassword query[kSecAttrAccount as String] = "a" query[kSecValueData as String] = "b" let result = SecItem
var query = [String:AnyObject]() query[kSecClass as String] = kSecClassGenericPassword query[kSecAttrAccount as String] = "a" query[kSecValueData as String] = "b" let result = SecItemAdd(query as CFDictionary, nil);
结果是-50.无法弄清楚为什么,需要帮助..在此先感谢.
我相信kSecValueData键的值需要是NSData,而不是String或NSString.尝试将字符串编码为数据(例如使用UTF-8编码).未经测试的片段:query[kSecValueData as String] = "b".dataUsingEncoding(NSUTF8StringEncoding)
为了将来参考,错误代码-50对应于errSecParam,SecBase.h头文件的含义为:“传递给函数的一个或多个参数无效.”如果再次看到此错误,请尝试使用查询字典更改传入的值.