ReactNative集成到已有工程中-IOS

如下步骤为手动添加的方式,使用rnpm的方式请参考官方文档。html

本文是对官方文档的一个补充,大部份内容来源于官网文档。node

官方参考地址: http://facebook.github.io/react-native/docs/linking-libraries-ios.html#contentreact

中文参考地址:http://reactnative.cn/docs/linking-libraries-ios.html#contentios

第一步:添加.xcodeproj文件

把须要的.xcodeproj文件,拖到你的XCode工程下(一般拖到XCode的Libraries分组里)git

clipboard.png

react-native须要集成的.xcodeproj文件清单以下:github

node_modules/react-native/React/React.xcodeproj
node_modules/react-native/Libraries/Image/RCTImage.xcodeproj
node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj
node_modules/react-native/Libraries/Text/RCTText.xcodeproj
node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj
node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj
node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj
node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj

第二步添加.a文件

点击你的主工程文件,选择Build Phases,而后把刚才所添加进去的.xcodeproj下的Products文件夹中的静态库文件(.a文件),拖到Link Binary With Libraries组内。npm

clipboard.png

第三步注册头文件路径-不是全部依赖都须要,注册React.xcodeproj便可

须要在原生代码中使用这个库,仍是只须要经过JavaScript访问?
若是你只须要经过JavaScript访问这个库,你就能够跳过这步了。react-native

打开你的工程文件,选择Build Settings,而后搜索Header Search Paths,而后添加库所在的目录(若是它还有像React这样的子目录须要包含,注意要选中recursive选项)xcode

clipboard.png

注意:React.xcodeproj是须要注册的。下面的目录要改为本身的目录。服务器

$(SRCROOT)/RN/node_modules/react-native/React

recursive

报错: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure

报错缘由是须要开启内网http的访问权限。

  1. 在Info.plist中添加 NSAppTransportSecurity 类型 Dictionary ;

  2. 在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 类型Boolean ,值设为 YES;

参考地址:

http://www.cnblogs.com/chglog/p/4746683.html

报错:unrecognized selector sent to instance

解决方案:

Build Settings -> other linker flags -> -ObjC

参考地址1:https://github.com/facebook/react-native/issues/2396

参考地址2:http://stackoverflow.com/questions/32775481/rctbatchedbridge-perfstats-unrecognized-selector-sent-to-instance

报错:RCTStatusBarManager module requires that the UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO

错误信息说的很清楚了。

在Info.plist中添加View controller-based status bar appearance为NO。

关闭自动启动调试服务器

在React.xcodeproj的Build Phases中的第一个(有8081那个)Run Script。用 <<! 代码代码代码 ! 注释掉便可。

clipboard.png

相关文章
相关标签/搜索