1.在工程文件夹下,增加package.json文件,如下:
{
"name": "RNTest1",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "15.3.1",
"react-native": "0.32.0"
}
}
2.在工程文件夹下下载node_modules文件
$ npm install
3.使用cocoaPod下载需要的Subspaces
1)cd到工程文件下(.xcodeproj所在的文件夹中),执行以下命令创建Podfile文件
$ pod init
2)Podfile内容如下,可以根据需要添加其他subspecs
target 'RNTest1' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for RNTest1
pod 'React', :path => './node_modules/react-native', :subspecs => [
'Core',
'RCTText',
'RCTNetwork’,
'RCTWebSocket', # needed for debugging
# Add any other subspecs you want to use in your project
]
end
3)使用cocoaPod下载
$ pod install
4.代码集成
1)在项目根目录下创建index.ios.js文件
$ touch index.ios.js
2)在需要的controller中,引入RCTRootView.h文件,使用