Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ffigen] Crash while evaluating a policy #1651

Open
matiasleyba opened this issue Oct 11, 2024 · 0 comments
Open

[ffigen] Crash while evaluating a policy #1651

matiasleyba opened this issue Oct 11, 2024 · 0 comments
Assignees
Labels
lang-objective_c Related to Objective C support package:ffigen

Comments

@matiasleyba
Copy link

Hi, I'm a beginner with ffigen but I'm trying to create an example using LocalAuthentication, I was able to generate the bindings and have created an implementation using them, everything works fine until I call evaluatePolicy and the app crashes.

Here is my implementation, I am assuming I have to call evaluatePolicy inside the platform thread as evaluatePolicy will do some ui stuff.

try {

      await runOnPlatformThread(() {
        final lib = DynamicLibrary.process();
        final localAuthentication = LocalAuthentication(lib);

        final context = LAContext.new1(localAuthentication);

        final error = NSError.new1(localAuthentication);

        final canEvaluate = context.canEvaluatePolicy_error_(
          LAPolicy.LAPolicyDeviceOwnerAuthentication,
          Pointer.fromAddress(error.pointer.address),
        );

        final completion = ObjCBlock_ffiVoid_bool_NSError.listener(
          localAuthentication,
          (result, nsError) {
            if (result) {
              return onSuccess();
            } else if (nsError != null) {
              onError();
            }
          },
        );

        final reason = NSString(localAuthentication, '');

        if (canEvaluate) {
          context.evaluatePolicy_localizedReason_reply_(
            LAPolicy.LAPolicyDeviceOwnerAuthentication,
            reason,
            completion,
          );
        }

        return;
      });
    } catch (e) {
      print(e);
    }

ffigen.yaml:

name: LocalAuthentication
description: Bindings for LocalAuthentication.
language: objc
output: 'lib/src/ffigen/local_auth_bindings.dart'
exclude-all-by-default: true
objc-interfaces:
  include:
    - 'LAContext'
headers:
  entry-points:
    - '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/LocalAuthentication.framework/Headers/LocalAuthentication.h'

Am I doing something wrong, does my use case make sense?

Let me know if you need more details, thanks in advance!

@dcharkes dcharkes added the lang-objective_c Related to Objective C support label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-objective_c Related to Objective C support package:ffigen
Projects
None yet
Development

No branches or pull requests

3 participants