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

Alexander Stolte

Expert
Licensed User
Longtime 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
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Here is enough old sample from my collection (works in IOS 14 also).
thank you ,it works.
But how do you handle this? Are you waiting for a result?
You have to wait for a result, whether the process was successful or not, so that nothing is loaded in the background.
 
Upvote 0

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
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Add Private result As Int to Process_Globals
hm, i put this in the process globals
B4X:
Private result As Int
but if i compile, this error occurs:
B4X:
error: use of undeclared identifier '__result'
it also does not work if i leave out the two underscores __result -> result
 
Upvote 0
Top