On some production devices our application fails to find the keychain item associated with our application where we store our JWT tokens. We have been unable to reproduce this in house for many months.
Today I restored a phone from a backup using the device to device transfer of data as I replaced my personal phone. On that device now when opened each time I am prompted to login again and it appears my token is never saved to the keychain. Upon every successive reopen of the application I see this error in the console.
Error fetching keychain item - Error Domain=NSOSStatusErrorDomain Code=-25300 "no matching items found" UserInfo={numberOfErrorsDeep=0, NSDescription=no matching items found}
I currently do not see any errors in the console related to the saving of said token.
We access this token with the after first unlock security and we do not allow iCloud backup for these tokens.
Any help here would be appreciated. I'm not sure what would cause an issue like this. Other applications on my device do not seem to have this issue, so Its likely something we're doing code wise that may be different. Any hints as to what to look for here may be of help. The previous device or any device i have not created from a backup works as intended, including about 95% of our production users.
The SecItem API is full of weird edge cases that can cause problems like this. I have lots of hints and tips on this topic in
I suspect you might be tripping over an item uniqueness problem, per the Uniqueness section of that first post.
I’m presuming that you can run a debug build on one of these affected devices. If so, add a test button that calls SecItemCopyMatching
to dump all of the items of your particular class. For example:
func dump() throws {
// `secCall(…)` is from https://developer.apple.com/forums/thread/710961
let items = try secCall { SecItemCopyMatching([
kSecClass: kSecClassGenericPassword,
kSecMatchLimit: kSecMatchLimitAll,
kSecReturnAttributes: true,
] as NSDictionary, $0) } as! [[String: Any]]
for item in items {
print(item)
}
}
That’ll tell you whether the items you’re adding are actually being added. If not, you can look at your SecItemAdd
copy. If they are, you can look at why you’re not finding them.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"