-
-
Save spnkr/5af4c274d511ffac01c5 to your computer and use it in GitHub Desktop.
RubyMotion Touch ID
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
# Call touch_id_authenticate | |
def touch_id_authenticate | |
context = LAContext.alloc.init | |
auth_error = nil | |
reason = 'Authenticate using your fingerprint' | |
if context.canEvaluatePolicy(LAPolicyDeviceOwnerAuthenticationWithBiometrics, error: auth_error) | |
context.evaluatePolicy(LAPolicyDeviceOwnerAuthenticationWithBiometrics, localizedReason: reason, reply: lambda do |success, error| | |
if success | |
Dispatch::Queue.main.async do | |
successful_authentication | |
end | |
else | |
# Customize Touch ID Failure | |
case error.code | |
when LAErrorAuthenticationFailed | |
auth_alert('Error', 'Authentication Failed') | |
break | |
when LAErrorUserCancel | |
auth_alert('Error', 'User pressed Cancel button') | |
break | |
when LAErrorUserFallback | |
auth_alert('Error', 'User pressed \'Enter Password\'') | |
break | |
else | |
auth_alert('Error', 'Touch ID is not configured') | |
break | |
end | |
end | |
end) | |
else | |
auth_alert('Error', 'No Touch ID on Device') | |
end | |
end | |
def auth_alert(title, message) | |
Dispatch::Queue.main.async do | |
@alert = UIAlertView.alloc.initWithTitle( | |
title, | |
message: message, | |
delegate: nil, | |
cancelButtonTitle: 'Dismiss', | |
otherButtonTitles: nil, | |
) | |
@alert.show | |
end | |
end | |
def successful_authentication | |
# Open a new screen, etc. | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment