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);
}
});