0

I am trying to bridge a call-back from native module to react native. I have tried this as well Got "is not a recognized Objective-C method" when bridging Swift to React-Native

I have added underscore to my first parameter as well

Following is my swift code

import Foundation
import LocalAuthentication

@objc(FingerPrintModule)
class FingerPrintModule: NSObject {
  
  var resultCallback: RCTResponseSenderBlock!
  
  @objc func authenticateLocallyForIos(_ callback: @escaping RCTResponseSenderBlock) -> Void {
    resultCallback = callback
    useLocalAuthentication()
  }
  
  private func useLocalAuthentication(){
    //Business logic
  }
  
}

I have created objective c file for my swift file as well

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <UIKit/UIKit.h>

@interface RCT_EXTERN_MODULE(FingerPrintModule, NSObject)


RCT_EXTERN_METHOD(authenticateLocallyForIos: callback:(RCTResponseSenderBlock)callback)
 
@end

When I call from react native I get error saying not recognised objective c method

my React Native code

import { NativeModules,
  Platform,
} from "react-native";
const { FingerPrintModule } = NativeModules;

Called on button press

FingerPrintModule.authenticateLocallyForIos((err, result) => {
        if (!err) {
          Alert.alert(result.toString());
        } else {
          Alert.alert(err);
        }
      });
BraveEvidence
  • 53
  • 11
  • 45
  • 119

2 Answers2

0

In your react code do something like below:

const yourModule = NativeModules.FingerPrintModule;

And then call method like below:

yourModule.authenticateLocallyForIos((err, result) => {
        if (!err) {
          Alert.alert(result.toString());
        } else {
          Alert.alert(err);
        }
      });
Daljeet
  • 1,573
  • 2
  • 20
  • 40
  • @Dalijeet I tried your way and get same error. Actually my way is correct one as it works on Android but for iOS it gives error. There is some mistake in method definition of my swift or objective c file – BraveEvidence Jul 27 '20 at 14:14
  • can you try creating simple method RCT_EXTERN_METHOD(sayHello) without any param and print hello in it – Daljeet Jul 27 '20 at 14:29
0

I have to change my objective c code to as follows

RCT_EXTERN_METHOD(authenticateLocallyForIos:(RCTResponseSenderBlock)callback)

BraveEvidence
  • 53
  • 11
  • 45
  • 119