Hello I am currently trying to query the keychain for my project without the kSecAttrAccountValue attribute and only using the kSecAttrServiceValue. Is this possible? The status says 0 however, the response is nil. I tried by adding an account and it works great! However, my goal is to obtain the result without it or all the results stored within the same service. Please let me know thank you!
Reference: Save and Load from KeyChain | Swift
Code:
let keychainQuery: NSMutableDictionary = NSMutableDictionary(objects: [kSecClassGenericPasswordValue, service, kCFBooleanTrue, kSecMatchLimitOneValue], forKeys: [kSecClassValue, kSecAttrServiceValue, kSecReturnDataValue, kSecMatchLimitValue])
var dataTypeRef :AnyObject?
// Search for the keychain items
let status: OSStatus = SecItemCopyMatching(keychainQuery, &dataTypeRef)
var contentsOfKeychain: String?
if status == errSecSuccess {
if let retrievedData = dataTypeRef as? Data {
contentsOfKeychain = String(data: retrievedData, encoding: String.Encoding.utf8)
}
} else {
print("Nothing was retrieved from the keychain. Status code \(status)")
}
return contentsOfKeychain