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類庫