前言:
尽管之前已经配置过几次iOS react-native-baidu-map,但是最近写工程配置还是出了些问题,(折腾半天,回退版本,重新配置了一次)。
项目环境
react @16.0.0
react-native @0.51.0
作者 gitHub地址:https://github.com/lovebing/react-native-baidu-map
配置环境说明:(这里我们只谈及iOS的xcode配置)
git上xcode配置过程:
1.Project navigator->Libraries->Add Files to 选择 react-native-baidu-map/ios/RCTBaiduMap.xcodeproj
2.Project navigator->Build Phases->Link Binary With Libraries 加入 libRCTBaiduMap.a
3.Project navigator->Build Settings->Search Paths, Framework search paths 添加 react-native-baidu-map/ios/lib,Header search paths 添加 react-native-baidu-map/ios/RCTBaiduMap
4.添加依赖, react-native-baidu-map/ios/lib 下的全部 framwordk, CoreLocation.framework和QuartzCore.framework、OpenGLES.framework、SystemConfiguration.framework、CoreGraphics.framework、Security.framework、libsqlite3.0.tbd(xcode7以前为 libsqlite3.0.dylib)、CoreTelephony.framework 、libstdc++.6.0.9.tbd(xcode7以前为libstdc++.6.0.9.dylib)
5.添加 BaiduMapAPI_Map.framework/Resources/mapapi.bundle
6.其它一些注意事项可参考百度地图LBS文档
AppDelegate.m init 初始化
#import "RCTBaiduMapViewManager.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[RCTBaiduMapViewManager initSDK:@"api key"];
...
}
注意的地方:
A.上述配置第3条中,Framework search paths 添加 $(SRCROOT)/../node_modules/react-native-baidu-map/ios/lib,Header search paths 添加$(SRCROOT)/../node_modules/react-native-baidu-map/ios/RCTBaiduMap
B.这次配置过程中也出现 git Issues 中#128问题,即“Redefinition of 'RCTMethodInfo'”,按照#128和#149给出的方法解决即可。
C.出现“'RCTViewManager.h' file not found”问题 按#100中方法,如下:
“导入后,有可能把react-native清除了,可以重新执行一次npm install
#import "React/RCTViewManager.h"
#import "React/RCTConvert+CoreLocation.h"
”