Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to log and delete keychain items from your iOS app?
func iterateKeychainItems(log: Bool, delete: Bool) {
let secItemClasses = [
kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity
]
if (log) {
for secItemClass in secItemClasses {
let query: [String: Any] = [
kSecReturnAttributes as String: kCFBooleanTrue,
kSecMatchLimit as String: kSecMatchLimitAll,
kSecClass as String: secItemClass
]
var result: AnyObject?
let status = SecItemCopyMatching(query as CFDictionary, &result)
if status == noErr {
print(result as Any)
}
}
print("AppUsageMetadata.iterateKeychainItems ended.")
}
if (delete) {
for secItemClass in secItemClasses {
let dictionary = [kSecClass as String:secItemClass]
SecItemDelete(dictionary as CFDictionary)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.