Home > OS >  iOS biometrics, how to create LAContext instance from C ?
iOS biometrics, how to create LAContext instance from C ?

Time:05-02

I'm trying to implement biometric authentication on iOS from a C codebase. Here is one example.

In order to achieve this, I need to use the LAContext obj-c APIs. However, when I try to initialize the class from C I get a pointer/reference error:

// Cannot initialize a variable of type 'LAContext *__strong' with an rvalue of type 'LAContext'
LAContext* authContext = LAContext();

Is there any way to achieve this? Or is this struct available from Obj-c only?

Edit 1:

My file is in Obj-C , so in theory I should be able to mix C and Obj-C code, however when I try to write a Obj-C function to alloc the LAContext object I get a missing symbols error:

-(bool)biometricsAvailable {
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    return true;
}

On the compilation step this error is thrown:

Undefined symbol: _OBJC_CLASS_$_LAContext

XCode itself does not show any error while editing the file, only happens when I try to build/compile the app.

CodePudding user response:

As it turns out, the problem was not with mixing C and Obj-C code, but rather with my library being linked via cocoapods and the LocalAuthentication framework being missing.

I needed to add:

s.frameworks = "LocalAuthentication" 

to the podspec and creating a LAContext instance works just fine.

  • Related