13135 . [ D5: React Native setNativeProps使用 (2016-8-24)] ( #d5react-native-setnativeprops使用2016-8-24 )
14146 . [ D6: ref 属性不只是string(2016-8-25)] ( #d6ref属性不只是string2016-8-25 )
15157 . [ D7:解构赋值(Destructuring assignment)(2016-8-26)] ( #d7解构赋值destructuring-assignment2016-8-26 )
16+ 8 . [ D8: React-Native 原生模块调用(iOS) (2016-8-29)] ( #d8react-native-原生模块调用(iOS)-2016-8-29 )
1617
1718```
1819模板:
@@ -26,6 +27,54 @@ D1:标题 (日期)
2627另外:记得在列表中添加链接
2728```
2829
30+ D8: React-Native 原生模块调用(iOS) (2016-8-29)
31+ ------
32+ 在项目中遇到地图,拨打电话,清除缓存等iOS与Andiorid机制不同的功能,就需要调用原生的界面或模块,这里说下React Native调用iOS原生模块,Andiorid也是大同小异
33+ ###1 .创建原生模块,实现“RCTBridgeModule”协议
34+ ```
35+ #import <Foundation/Foundation.h>
36+ #import "RCTBridgeModule.h"
37+
38+ @interface KSDMapManager : NSObject <RCTBridgeModule>
39+
40+ @end
41+ ```
42+ ###2 导出模块,导出方法
43+ ```
44+ @implementation KSDMapManager
45+ //导出模块
46+ RCT_EXPORT_MODULE();
47+
48+ RCT_EXPORT_METHOD(gotoIM:(RCTResponseSenderBlock)callback)
49+ {
50+ __weak typeof(self) weakSelf = self;
51+ self.callback = callback;
52+
53+ UIViewController *controller = (UIViewController*)[[[UIApplication sharedApplication] keyWindow] rootViewController];
54+ KSDMapLocationViewController *mapVc = [[KSDMapLocationViewController alloc] init];
55+ mapVc.handle = ^(NSString *address) {
56+ weakSelf.itemValue = address;
57+ NSArray *events = [[NSArray alloc] initWithObjects:self.itemValue, nil];
58+ callback(events);
59+ };
60+ [controller presentViewController:mapVc animated:YES completion:nil];
61+ }
62+
63+ ```
64+
65+ ###3 js文件中调用
66+ ```
67+ //创建原生模块实例
68+ var KSDMapManager = NativeModules.KSDMapManager;
69+ //方法调用
70+ KSDMapManager.gotoIM(
71+ (events)=>{
72+ this._inputReceiveAddress(events);
73+ console.log(events);
74+ })
75+
76+ ```
77+
2978D7:解构赋值([ Destructuring assignment] [ 0 ] )(2016-8-26)
3079------
3180解构赋值语法是JavaScript的一种表达式,可以方便的从数组或者对象中快速提取值赋给定义的变量。
0 commit comments