Created
June 26, 2017 11:27
-
-
Save dirtyhenry/46a87f9a3717532085974edcfa114051 to your computer and use it in GitHub Desktop.
How to log and delete keychain items from your iOS app?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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