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

Add Objective-C support #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Eradash
Copy link

@Eradash Eradash commented Aug 14, 2019

I needed to use this library inside an Objective-C project. This is the modifications I've done to make it work.

@rushisangani
Copy link
Owner

@Eradash thanks for the effort.
I think you should use this in swift only.
You can use it by creating by the following:

  • Create a Swift extension
  • Add a method to show the menu, marked in @objc.

:)

@Eradash
Copy link
Author

Eradash commented Aug 14, 2019

The problem comes with the callback... The method can't be marked with @objc with this parameter. With the protocol, it's possible to have the Objective-C support easily in the library.
I can't change all my project to swift, that's why I adapted this library. Feel free to close this PR if it's not appropriate ;)

@rushisangani
Copy link
Owner

@Eradash can you please show how you're calling the library function from your objective c?
I will give it a try to solve it.

@Eradash
Copy link
Author

Eradash commented Aug 14, 2019

My class is implementing the new protocol, so the biometricResultOK and biometricError are defined (for the callback). I simply call the authentication method of the library with self as the callback class.

- (void)biometricResultOK {
}

- (void)biometricErrorWithError:(enum AuthenticationErrorOBJC)error {
}

- (void)authenticate:(UITapGestureRecognizer *)gesture {
    [BioMetricAuthenticator authenticateWithPasscodeWithReason:@"Test" cancelTitle:@"Cancel test" completion:self];
}

@rushisangani
Copy link
Owner

rushisangani commented Aug 14, 2019

@Eradash why do you want to go with the protocol approach?
when you already have a complete block with success or failure?

I agree that may be swift completion with result type is not accessible from the objc,
but ideal approach should be making an extension in swift and open a menu from it.

Converting or making it reverse compatible with objc is not a good solution though.
Project build time will increase when you increase the conversion to/from with objc/swift.

@Eradash
Copy link
Author

Eradash commented Aug 14, 2019

I'm quite new to Objective C and Swift, and this solution was the fastest and easiest way for me to make the library works

@rushisangani
Copy link
Owner

 import BiometricAuthentication

    extension ViewController {
    
    @objc func presentBiometricAuthentication()  {
      // swift code here (check the example)
    }

@Eradash
Copy link
Author

Eradash commented Aug 14, 2019

This will create a real mess in every project in objc that wants to implement your library. It creates a other file were code can be, and debugging and maintainability are affected. I don't intend to make the switch to Swift in my project, and I think I'm not the only one only for a library.
That's why I proposed the solution to make the library compatible with objc. This way, someone can simply import the library, and use it easily in the objc code. I agree it's not the ideal solution. I don't know how to make a proper callback compatible with objc and swift. I proposed my changes to help other dev stuck with objc, and maybe someone knows how to make the library more efficient with objc easily ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants