1.安装CocoaPods。
2.安装Node.js。
3.在要集成ReactNative项目的根目录下安装react-native:
npm install react-native
如果成功的话,项目的根目录下就会出现 node_modules 文件夹
4在项目的根目录下新建一个名为Podfile的文件,打开文件,填入下面的文本:
# Depending on how your project is organized, your node_modules directory may be
# somewhere else; tell CocoaPods where you've installed react-native from npm
pod 'React', :path => './node_modules/react-native', :subspecs => [
'Core',
'RCTImage',
'RCTNetwork',
'RCTText',
'RCTWebSocket',
# Add any other subspecs you want to use in your project
]
5.执行命令:
pod install
6.在项目的根目录下创建一个名称为ReactComponent的文件夹:
mkdir ReactComponent
执行完之后创建一个名称为index.ios.js的文件:
touch ReactComponent/index.ios.js
在index.ios.js的文件中填入要执行的js代码即可。
7.请参考官方文档:点击打开链接
8.注意事项:项目中一定要添加libReact.a类库