The documentation that Apple has provided for TouchID implementation for iOS 8 is in Objective-C.
Is there a Swift version of it?
Objective-C:
- (IBAction)touchIDAvailable:(UIButton *)touchIDAvailableButton {
LAContext *context = [[LAContext alloc] init];
__block NSString *msg;
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Place your finger on the sensor", nil) reply: ^(BOOL success, NSError *authenticationError) {
if (success) {
}
}
}
Swift:
@IBAction func touchidbutton(sender: AnyObject) {
authContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Place your finger on the sensor"?, reply: ((success : Bool, NSError!) -> Void)?){
if (success) {
}
}
}
Found it!
The link below is from a user named Shmoopi from Github. Shmoopi made the app to test the TouchID programmed in Swift.
https://github.com/Shmoopi/Swift-Touch-ID
Here is my view controller that does these checks in Swift. While working on this I found the completion block/closure syntax in Swift to be very confusing.
Notice that some of the options changed in Beta 2 in order to give you more control over the Touch ID dialog such as disabling the fallback option or the cancel button.
}
The API name is
LAContext
, and it's in the docs right here. It's pretty sparse, but it does its job. The method you probably want isThe string argument is a subheader to display to the user, the reply is simply a callback block, and the policy currently has to be
LAPolicy.DeviceOwnerAuthenticationWithBiometrics
, but it appears the framework is there for other types of authentication in the future. Interesting...Hope that helps! I tried on my phone because I was curious and it works wonderfully. Just make sure to query for ability to evaluate policy before you try to use it, in case it's on an older device.
Swift 3.0 in:
The LAContext reference has method signatures in both Obj-C and Swift. Furthermore, if you ⌘-click on the LAContext class in your Swift code, you should be able to view the generated "header" for it in Swift.
Updated to Swift 3