问题描述
我正在尝试更新现有钥匙串条目中的密码,但失败并显示以下消息:
无法更新钥匙串中的令牌:传递给函数的一个或多个参数无效。
我可以毫无问题地更新帐户名称,还可以创建钥匙串元素。不知道为什么更新失败。我在MacOs Catalina上使用XCode 11.6。
我们将不胜感激:-)
// try to update first
let updateQuery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,kSecAttrService as String: LocalKeychainStorage.KEYCHAIN_LABEL,kSecAttrAccount as String: LocalKeychainStorage.ACCOUNT_LABEL
]
let attributes: [String: Any] = [kSecValueData as String: credentials.token]
let status = SecItemUpdate(updateQuery as CFDictionary,attributes as CFDictionary)
guard status != errSecItemNotFound else {
// try to add it,as it was not found
let addQuery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,kSecAttrAccount as String: LocalKeychainStorage.ACCOUNT_LABEL,kSecValueData as String: credentials.token]
let status = SecItemAdd(addQuery as CFDictionary,nil)
guard status == errSecSuccess else {
throw LocalKeychainStorageError.keychainAddFailed(status: status)
}
print("Add to keystore for \(LocalKeychainStorage.KEYCHAIN_LABEL) successful")
return
}
guard status == errSecSuccess else {
let errorString: String = SecCopyErrorMessageString(status,nil)! as String
throw LocalKeychainStorageError.keychainUpdateFailed(status: errorString)
}
print("Update of keystore for \(LocalKeychainStorage.KEYCHAIN_LABEL) successful")
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)