简体   繁体   中英

What does OSStatus Error -50 mean?

I am writing some keychain code on iOS. When I try to insert an item in keychain I get error -50.

What does OSStatus error -50 mean?

If you are adding a password to the keychain make sure you pass it as Data and not String, otherwise you will get an OSStatus error -50.

static func savePassword(password: Data, account: String) throws -> OSStatus {
    let query = [
        kSecClass as String: kSecClassGenericPassword as String,
        kSecAttrAccount as String: account,
        kSecValueData as String: password
        ] as [String: Any]

    SecItemDelete(query as CFDictionary)

    return SecItemAdd(query as CFDictionary, nil)
}

Error -50 is a errSecParam , and means that at least one of the parameters you passed in a function was/are not valid.

This can be due to type differences, or perhaps an invalid value. See this page on the Apple site to read the official documentation from Apple on errSecParam .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM