当我尝试使用SecItemAdd()
在命令行Swift应用程序中使用参数kSecAttrSynchronizable
将项添加到macOS钥匙串时,我收到错误-50 (One or more parameters passed to the function were not valid)
。如果我删除kSecAttrSynchronizable
,它可以正常工作。我已尝试使用KeychainAccess并尝试手动执行(使用macOS提供的keychain服务API),结果相同。
import Foundation
let account = "username"
let password = "password".data(using: String.Encoding.utf8)!
var query: [String: Any] = [kSecClass as String: kSecClassInternetPassword,
kSecAttrAccount as String: account,
kSecAttrServer as String: "nabeelomer.me",
kSecAttrSynchronizable as String: kCFBooleanTrue,
kSecValueData as String: password]
let status = SecItemAdd(query as CFDictionary, nil)
print(status)
是否可能存在应用程序需要的无证权限?
Swift 4.0,macOS 10.13.3,Xcode 9.1