secItemAdd快速保持返回-50错误 [英] secItemAdd keep return -50 error in swift
问题描述
尝试在安全链中添加项目时保持-50.
Keep getting -50 when trying to add an item in security chain.
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.无法弄清楚原因,需要帮助..在此先感谢.
result is -50. Can not figure out why, need help.. thanks in advance.
推荐答案
我相信kSecValueData
键的值必须是NSData,而不是String或NSString.尝试将字符串编码为数据(例如UTF-8编码).未经测试的代码段:
I believe the value for the kSecValueData
key needs to be an NSData, not a String or NSString. Try encoding your string to data (with e.g. UTF-8 encoding). Untested snippet:
query[kSecValueData as String] = "b".dataUsingEncoding(NSUTF8StringEncoding)
为将来参考,错误代码-50对应于errSecParam
,SecBase.h标头中的错误代码表示为:传递给函数的一个或多个参数无效."如果再次遇到此错误,请尝试更改查询字典中传递的值.
For future reference, the error code -50 corresponds to errSecParam
, which the SecBase.h header documents as meaning: "One or more parameters passed to a function were not valid." If you see this error again, try changing the values that you're passing in with your query dictionary.
这篇关于secItemAdd快速保持返回-50错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!