1.首先react-native init 一个初始react-native项目,然后找到ios目录,把ios目录中的项目工程全部删除。(注意事项:在删除之前务必记住这些工程的名字和路径待会第三步需要用到)如下图:1.0

2.然后把你需要导入的iOS项目copy或者拖到刚刚上一步的ios目录中(如下图1.1),这时打开iOS项目务必运行下,检查下项目是否能编译成功。

3.在XCode左侧文件栏中新建一个Libraries文件,然后把第一步的那些工程文件(在node_modules/react-native/React目录中)拖入到这文件目录上图1.0:
4.然后在TARGETS找到对应项目的名,点击项目名->Builid Phases->Link Binary With Libraries:
把对应1.0图的**.xcodeproj的.a文件加入进去如下图3.0:

5.然后在Builid Phases中新建run Script Phase名字修改为Bundle React Native code and images。然后shell脚本添加路径如下图:
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh


5.打开Edit Scheme界面:添加React如下6.0图配置下:

6.在Build Settings中找到 Other Linker Flags 填写上$(inherited),-ObjC,-lc++这三个链接器参数。如下图7.0

7.Bulid Settings中找到 Header Search Paths 添加$(SRCROOT)/../node_modules/react-native/React 路径(注意这个路径是相对你的项目工程.xcodeproj)。如下图8.0

8.最后检查下Build Active Architecture Only是否如下图9.0:

最后你就可以运行你的react-native的工程。
网友评论