Keychain delete not work

Hello, I have problem with delete item from keychain. I use this code in my app. result code is state = 0 . Item in keychain was not deleted.

 let query2 = [

                          kSecClass: kSecClassGenericPassword,

                          kSecAttrService: "xx.xx.xx"

                        ] as CFDictionary

var state =  SecItemDelete(query2) print("Operation finished with status delete: (state)")

I have problem with delete item from keychain.

What platform are you working on?

And if it’s the Mac, make sure you read On Mac Keychains before continuing (-:

Finally, you’ve tagged your question with Passkeys in iCloud Keychain and iCloud Keychain Verification Codes. Did you do that because they happen to have keychain in the name? Or are you specifically working with those technologies?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I work with IOS 15, IpadOS 15, WatchOS 8.5.

The application works by passing information for verification from the iPhone to the Watch via a keychain. But I need the event to delete data from the KeyChain, which is synchronized with Icloud. I use the application primarily on the iPhone, here does not work deleting or updating the Keys in the keychain.

Thanks you for your help.

I work with IOS 15, IpadOS 15, WatchOS 8.5.

OK, that simplifies things.

The application works by passing information for verification from the iPhone to the Watch via a keychain.

So, you’re not specifically working with Passkeys in iCloud Keychain and iCloud Keychain Verification Codes. Cool. I’ve removed those tags.

I use the application primarily on the iPhone, here does not work deleting or updating the Keys in the keychain.

Please clarify what you mean by “does not work”. Do you get an error back from SecItemDelete? Or does it return errSecSuccess and yet the key remains in the keychain?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The dictionary you pass to SecItemDelete is a query dictionary. IIRC it’ll return success if the query doesn’t find anything.

Try this:

  1. Reproduce the problem with SecItemDelete.

  2. Then add kSecReturnAttributes to your query dictionary and call SecItemCopyMatching. What do you get back?

  3. If SecItemCopyMatching failed with errSecItemNotFound, remove kSecAttrService and try again. What does that return?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Keychain delete not work
 
 
Q