Native的方法,还需要对结果进行处理,这样就需要使用JavaSctipt的回调函数,对结果进行处理。在React Native中Object-c有两种方式的回调:RCTReponseSenderBlock和Promises。
iOS端以promise形式返回数据与Android不同,Android端定义了一个Promise类,iOS端还是通过block形式给出回调,使用RCTPromiseResolveBlock和RCTPromiseRejectBlock。
RN与原生交互——传参并带有回调
RN与原生交互(二)——数据传递
React Native知识12-与原生交互
react-native调用ios native方法-回调
React Native填坑之旅--与Native通信之iOS篇
//MARK:钥匙申请 按钮
//申请数字钥匙前,获取 挑战码
//deviceId 物联网终端设备的设备号
//numberPlates 车牌号
//PEPS PEPS无钥匙入车 默认 false:不支持 true:支持
//- (void)KeyApplyClick_new:(NSString *)templateId numberPlates:(NSString *)numberPlates numberVehicle:(NSString *)numberVehicle phonenumber:(NSString *)phonenumber RNsuccess:(RNSuccessBlock)RNsuccess RNfailure:(RNFailureBlock)RNfailure;
RCT_REMAP_METHOD(KeyApplyClick_new,KeyApplyClick_new:(NSString *)templateId numberPlates:(NSString *)numberPlates numberVehicle:(NSString *)numberVehicle phonenumber:(NSString *)phonenumber KeyApplyClick_newresolve:(RCTPromiseResolveBlock)resolve KeyApplyClick_newreject:(RCTPromiseRejectBlock)reject)
{
[[GNUserManager_rn instance] KeyApplyClick_new:templateId numberPlates:numberPlates numberVehicle:numberVehicle phonenumber:phonenumber RNsuccess:^(id result) {
resolve(result);
} RNfailure:^(id result) {
reject(@"no_events", @"There were no events", result);
}];
}
网友评论