B4i Library iOS - TouchID

Hi All,

This code will allow to use the TouchID (Fingerprint) in your app.
The example is on a button named Button with click event.

I was thinking to build a class for this but I think this is more comfortable to copy the source and modify the subs.


B4X:
#PlistExtra: <key>NSFaceIDUsageDescription</key<string>Uses face id to allow authentication</string>
Sub Button_Click
ShowTouchID(Me,"TouchOK", "TouchFail")
End Sub


Sub ShowTouchID(SubHandler As Object, ApprovedSub As String, FailSub As String)
Dim noMe As NativeObject=Me
noMe.RunMethod("TouchID:::",Array(SubHandler,ApprovedSub,FailSub))
End Sub

Sub TouchOK
Log("Touch Approved")
End Sub

Sub TouchFail(ErrorDescription As String)
Log(ErrorDescription)
End Sub

#If OBJC

#import <LocalAuthentication/LocalAuthentication.h>

-(void)TouchID :(NSObject*)handler :(NSString*) subnameok :(NSString*) subnamefail
{
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Used for quick and secure access to the test app";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:myLocalizedReasonString
                            reply:^(BOOL success, NSError *error) {
            if (success) {
                [self.__c CallSubDelayed:self.bi :handler :(subnameok)];
            } else {
                [self.__c CallSubDelayed2:self.bi :handler :(subnamefail) :(error.localizedDescription)];
            }
        }];
} else {
[self.__c CallSubDelayed2:self.bi :handler :(subnamefail) :(authError.localizedDescription)];

}
}


#End If


Ask if you have any questions

Narek
 
Last edited by a moderator:

Mike1970

Well-Known Member
Licensed User
Longtime User
It took me exactly 3 seconds to see that you haven't carefully checked the text as I've asked you to...
Sorry... I didn’t understand where actually ..

Edit: I didn’t understand that with “text attribute” you was meaning the plisextra.
I was looking in the objective C code...
I now found out that in the @narek adonts PlisExtra an “<\key>” is wrote incorrectly , the “>” is missing
 
Last edited:
Top