B4i Library iOS - TouchID

Discussion in 'iOS Libraries' started by narek adonts, Jun 14, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    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.


    Code:
    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: Jun 16, 2015
  2. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi.
    What is TouchID?
     
  3. narek adonts

    narek adonts Well-Known Member Licensed User

    FingerPrint that the iPhones 5S + support
     
    omidaghakhani1368 likes this.
  4. ilan

    ilan Expert Licensed User

    thanks narek this is great!! now i only need an iphon5+ to test it :)
     
  5. mcGeorge

    mcGeorge Member Licensed User

    Thanks narek. Great!
     
  6. leBasic

    leBasic Member Licensed User

    Thanks Narek!
    Is there a way to test if the device has a touch id sensor before calling the ShowTouchID sub? I think the sub will return an error, but it would be nice to test it without making a touch id request (for example to show or not an option in a settings panel)
     
  7. narek adonts

    narek adonts Well-Known Member Licensed User

    You can call the sub and check the error description. It would be something like not supported.
     
  8. leBasic

    leBasic Member Licensed User

    But if supported it will show the touch id input request, right?
     
  9. narek adonts

    narek adonts Well-Known Member Licensed User

    maybe this

    Code:
    Sub CheckTouchID As Boolean
    return nome.runMethod("CheckTouchID",Null).AsBoolean
    End Sub

    #If OBJC

    -(BOOL)CheckTouchID
    {
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;

    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        return YES;
    }
    else
    {
    return NO;

    }
    }

    #End If
    But This will return false also when passcode is not set.
     
    mrred128, Erel and leBasic like this.
  10. leBasic

    leBasic Member Licensed User

    Thanks Narek! I think it will be useful to a lot of B4i developers!
     
  11. Brian Robinson

    Brian Robinson Active Member Licensed User

    schimanski likes this.
  12. schimanski

    schimanski Well-Known Member Licensed User

    After 'Touch Approved", how do I prevent the TouchID-Window from showing again and again?
     
  13. narek adonts

    narek adonts Well-Known Member Licensed User

    Didnt understood your question. The dialog is shown only when u ask to show.
     
  14. schimanski

    schimanski Well-Known Member Licensed User

    Then i think it was my mistake. I call show in application_active. So it seems, that this sub is always called after closing the touchID-window. I will change the code tomorrow...
    Thanks for your reply...
     
  15. schimanski

    schimanski Well-Known Member Licensed User

  16. Krammig

    Krammig Member Licensed User

    Hello Narek, Thank you for this contribution.

    I am new to B4i so I was wondering if you have a small example complete project that uses this and shows how it all works ?

    thanks
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    You should add this line (change the description as needed):

    Code:
    #PlistExtra:<key>NSFaceIDUsageDescription</key><string>Uses face id to allow authentication</string>
    Otherwise the app may crash on new devices.
     
    narek adonts likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice