I am attempting to send base64 image string to swift and I would like the classification of the image returned to me in my call back. However, I can pass a string, and I can pass a callback individually with success, but when I add them together I am receiving:
Exception 'bothClassifyAndCallback: is not a recognized Objective-C method.
Here is my bridge.m - note methods classify and myCallback work just fine
#import "React/RCTBridgeModule.h"@interface RCT_EXTERN_MODULE( ImageClassifier, NSObject ) RCT_EXTERN_METHOD( classify: (NSString*)img ) RCT_EXTERN_METHOD( myCallback: (RCTResponseSenderBlock)callback ) RCT_EXTERN_METHOD( bothClassifyAndCallback: (NSString*)img (RCTResponseSenderBlock)callback)@end
Here is my bridge.swift file
import Foundation@objc( ImageClassifier )class ImageClassifier: NSObject { @objc func classify( _ img: String ) { print( img ) } @objc func myCallback( _ callback: RCTResponseSenderBlock ) { callback([ "From swift to js" ]) } @objc func bothClassifyAndCallback( _ img: String, _ callback: RCTResponseSenderBlock ) { print( img ) return callback( [ "recieving and returning to js" ] ) } @objc static func requiresMainQueueSetup() -> Bool { return true }}
And here is my call in react native
class BridgeTest extends React.Component { constructor(){ super() this.classifier = NativeModules.ImageClassifier } onPress = () => { this.classifier.classify( "from js" ) // this works this.classifier.myCallback( ( arg ) => { console.log( "my arg is" + arg ) } ) // This works this.classifier.bothClassifyAndCallback( "argument", ( arg ) => { console.log( "my arg is " + arg ) })}render() { return( <Button title="bridge" onPress={this.onPress}></Button> )}export default BridgeTest}
I suspect I am wrong here:
RCT_EXTERN_METHOD( bothClassifyAndCallback: (NSString*)img (RCTResponseSenderBlock)callback)
But after trying several variations I just can't get it to work. Thanks.