React-Native与iOS数据交互-iOS端

2018-12-14  本文已影响0人  捕梦少女的梦想

新建继承NSObject的数据类NativeCommon

.h文件

#import <React/RCTBridgeModule.h>
#import <React/RCTLog.h>
#import <React/RCTEventEmitter.h>

.m文件

RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(goAliVerifyPage) {
}
RCT_EXPORT_METHOD(addHelloWord:(NSString *)name location:(NSString *)location){
  RCTLogInfo(@"带参数---->name=%@,location=%@",name,location);
}
RCT_EXPORT_METHOD(checkIsRoot:(RCTResponseSenderBlock)callback {
  NSArray *array = @[@"string", @"number"];
  callback(array);
}
RCT_EXPORT_METHOD(getHBDeviceUniqueID:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject) {
NSArray *events =@[@"Promise ",@"test ",@" array"];
    if (events) {
        resolve(events);
    } else {
        NSError *error=[NSError errorWithDomain:@"我是回调错误信息..." code:101 userInfo:nil];
        reject(@"no_events", @"There were no events", error);
    }
}
上一篇下一篇

猜你喜欢

热点阅读