SecItemCopyMatching kSecUseKeychain

Can kSecUseKeychain be used with SecItemCopyMatching?


I'm trying to find a way to display to the user on which KeyChain some items are.

Answered by DTS Engineer in 290585022

Can

kSecUseKeychain
be used with
SecItemCopyMatching
?

No.

kSecUseKeychain
is only relevant when adding items. The doc comments in the header are pretty clear about this:

You use this key to specify a value of type

SecKeychainRef
to which
SecItemAdd
will add the provided item(s).

The droid you’re looking for is

kSecMatchSearchList
. It’s doc comments say:

If provided, the search will be limited to the keychains contained in this list.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

Can

kSecUseKeychain
be used with
SecItemCopyMatching
?

No.

kSecUseKeychain
is only relevant when adding items. The doc comments in the header are pretty clear about this:

You use this key to specify a value of type

SecKeychainRef
to which
SecItemAdd
will add the provided item(s).

The droid you’re looking for is

kSecMatchSearchList
. It’s doc comments say:

If provided, the search will be limited to the keychains contained in this list.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks man, as usual you're always incredibly helpful.


I noticed the comment in the header file, but when I double checked online, (by navigating through the SecitemCopyMatching) it showed the key, so I completlated if it was a documentation mistmatch and tried it.


I really appreciate the pointer, as the only other solution I'd found was using SecKeychainSetSearchList and while it worked, there was one time when it didn't and it erased my Keychain, thankfully I had a backup. However it made me too nervous to include it a customer facing application.

SecItemCopyMatching kSecUseKeychain
 
 
Q