iOS Question TouchID - error: property '__c' not found on object of type

Similar threads

B4i Tutorial Local Mac Builder Installation
B4i Library iOS - TouchID
B4i Question Compile Fails
B4i Question [SOLVED] TouchID / FaceID Objective C error
B4i Question B4i-Bridge problems

Alexander Stolte

Expert
Licensed User
I'm using this code:
B4X:
#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
If i compile i get this error:
B4X:
/Users/alexanderstolte/Dropbox/XXX/B4iBuildServer/UploadedProjects/<user id>/B4iProject/b4i_main.m:245:23: error: property '__c' not found on object of type 'B4IViewController *'
                [self.__c CallSubDelayed:self.bi :handler :(subnameok)];
                      ^
/Users/alexanderstolte/Dropbox/XXX/B4iBuildServer/UploadedProjects/<user id>/B4iProject/b4i_main.m:247:23: error: property '__c' not found on object of type 'B4IViewController *'
                [self.__c CallSubDelayed2:self.bi :handler :(subnamefail) :(error.localizedDescription)];
                      ^
/Users/alexanderstolte/Dropbox/XXX/B4iBuildServer/UploadedProjects/<user id>/B4iProject/b4i_main.m:251:7: error: property '__c' not found on object of type 'B4IViewController *'
[self.__c CallSubDelayed2:self.bi :handler :(subnamefail) :(authError.localizedDescription)];
what is missing?
 

Semen Matusovskiy

Well-Known Member
Licensed User
Here is enough old sample from my collection (works in IOS 14 also).
B4X:
#IF OBJC
   
#import <LocalAuthentication/LocalAuthentication.h>
- (void) authenticateButtonTapped {
   
   LAContext *context = [[LAContext alloc] init];
   NSError *error = nil;
   if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
       [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
               localizedReason:@"Are you the device owner?"
                         reply:^(BOOL success, NSError *error) {

           if (error) {
               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                               message:@"There was a problem verifying your identity."
                                                              delegate:nil
                                                     cancelButtonTitle:@"Ok"
                                                     otherButtonTitles:nil];
               [alert show];
               return;
           }

           if (success) {
               NSLog (@"You are the device owner!");
           } else {
               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                               message:@"You are not the device owner."
                                                              delegate:nil
                                                     cancelButtonTitle:@"Ok"
                                                     otherButtonTitles:nil];
               [alert show];
           }

       }];

   } else {

       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                       message:@"Your device cannot authenticate using TouchID."
                                                      delegate:nil
                                             cancelButtonTitle:@"Ok"
                                             otherButtonTitles:nil];
       [alert show];

   }
}
#End If
You can call it
B4X:
    Dim no As NativeObject = Me
    no.RunMethod ("authenticateButtonTapped", Null)
When appears a question Are you the device owner, touch Home button
 

Semen Matusovskiy

Well-Known Member
Licensed User
There are different ways. If you need modal solution, you can do following.

1) Add Private result As Int to Process_Globals

2) Objective-C (I replaced alerts to __result = ...)

B4X:
#IF OBJC
 
#import <LocalAuthentication/LocalAuthentication.h>
- (void) authenticateButtonTapped
    {
   __result = -1;   
   LAContext *context = [[LAContext alloc] init];
   NSError *error = nil;
   if ([context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error: &error])
       {
       [context evaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason: @"Are you the device owner?" reply: ^(BOOL success, NSError *error)
           {
           if (error) { __result = 2; return; };
           if (success) { __result = 0; } else { __result = 1; };
           }
       ];
       } 
    else
       { __result = 3; };
    }

#End If
3) In Application_Start (or somewhere else) add following code
B4X:
    Dim no As NativeObject = Me
    no.RunMethod ("authenticateButtonTapped", Null)
    Do While result < 0
        Sleep (50)
    Loop
    Select Case result
        Case 0    
            xui.MsgboxAsync ("Success: You are the device owner", "B4X")
        Case 1
            xui.MsgboxAsync ("Error: You are not the device owner", "B4X")
        Case 2
            xui.MsgboxAsync ("Error: There was a problem verifying your identity", "B4X")
        Case 3
            xui.MsgboxAsync ("Error: Your device cannot authenticate using TouchID", "B4X")
    End Select
 
Top