First of all, why is touch id "enabled" to every app but not face id. So if you have touch id set up every app can use it, but face id requires for user to accept it for every app.
How to find if user enabled face id for my app.
This is code i use to find out type of autentification
let hasAuthenticationBiometrics = myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
let hasAuthentication = myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)
if #available(iOS 11.0, *) {
if hasAuthentication {
if hasAuthenticationBiometrics {
switch myContext.biometryType {
case .none: return .none
case .faceID: return .faceID // Find out if it is enabled
case .touchID: return .touchID
}
} else {
return .passcode
}
} else {
return .none
}
} else {
if hasAuthentication {
if hasAuthenticationBiometrics {
return .touchID
} else {
return .passcode
}
} else {
return .none
}
}
If user has face id but disabled it for my app, i always get that he "has" face id even though my app is authenticated with passcode?
Found the answer, you use error pointer to find out if user disabled face id.
var error: NSError?
let hasAuthenticationBiometrics = myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
let hasAuthentication = myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)
if #available(iOS 11.0, *) {
if hasAuthentication {
if hasAuthenticationBiometrics {
switch myContext.biometryType {
case .none: return .none
case .faceID: return error?.code == -6 ? .passcode : .faceID // If user disabled face id in settings use passcode
case .touchID: return .touchID
}
} else {
return .passcode
}
} else {
return .none
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.