Native modules callback test project for iOS
cd ios/
in my example MyObjcClass.h
And, insert the following code
#import <React/RCTBridgeModule.h>
@interface MyObjcClass : NSObject <RCTBridgeModule>
@end
in my example MyObjcClass.m
And, Insert the following code
#import "MyObjcClass.h"
@implementation MyObjcClass
RCT_EXPORT_MODULE()
- (NSDictionary *)constantsToExport {
return @{@"greeting": @"Testing reactNative CallBack!"};
}
RCT_EXPORT_METHOD(squareMe:(NSString *)number:(RCTResponseSenderBlock)callback) {
NSNumber *num = @([number intValue]);
NSNumber *myValue = @([num integerValue] * [num integerValue]);
NSLog(@"----------------%@",myValue);
callback(@[[NSNull null], [NSNumber numberWithInt:([myValue integerValue])]]);}
@end
in my example, App.js
var MyObjcClass = require('NativeModules').MyObjcClass;
MyObjcClass.squareMe(num, (error, number) => {
if (error) {
console.error(error);
} else {
this.setState({number: number});
}
})