I want to authenticate only using the PassCode even device has the Touch ID Feature. I'm using .deviceOwnerAuthentication evaluate policy method. when I use this,
- If user has enrolled touch id --> alway ask for touch id
- If use hasn't enrolled touch id --> then only ask for passcode
what I want is, even user has enrolled for the touch id, ask only for the passcode. hope your help with this.
This can be done using Security framework using SecAccessControl by setting SecAccessControlCreateFlags as .devicePasscode.
Add a keychain item,
let secAccessControlbject: SecAccessControl = SecAccessControlCreateWithFlags(kCFAllocatorDefault,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
.devicePasscode,
nil)!
let dataToStore = "AnyData".data(using: .utf8)!
let insertQuery: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrAccessControl: secAccessControlbject,
kSecAttrService: "PasscodeAuthentication",
kSecValueData: dataToStore as Any,
]
let insertStatus = SecItemAdd(insertQuery as CFDictionary, nil)
To authenticate with the Passcode screen access the saved item,
let query: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrService : "PasscodeAuthentication",
kSecUseOperationPrompt : "Sign in"
]
var typeRef : CFTypeRef?
let status: OSStatus = SecItemCopyMatching(query, &typeRef) //This will prompt the passcode.
if (status == errSecSuccess)
{
print("Authentication Success")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With