当前位置: 首页 > 工具软件 > REACT-CPP > 使用案例 >

ios集成react-native步骤

蓟捷
2023-12-01
1.搭建开发环境可参考


2.然后使用xcode创建一个project文件

3.在项目根目录下创建 文件夹如 : react

4.在react文件夹下创建 package.json文件

{

  "name": "reactNativeTestProject”,//文件名
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.0.0-alpha.6",
    "react-native": "^0.44.0"
  },
  "devDependencies": {
    "babel-jest": "20.0.1",
    "babel-preset-react-native": "1.9.1",
    "jest": "20.0.1",
    "react-test-renderer": "16.0.0-alpha.6"
  },
  "jest": {
    "preset": "react-native"
  }
}

在react文件夹下安装react-native
npm install

4.在根目录下面创建Podfile文件内容如下
platform :ios, '8.0'
target 'reactNativeTestProject' do
  react_native_path = "./react/node_modules/react-native”  #在podfile所在的目录下找到node_modules文件夹
  pod "Yoga", :path => "#{ react_native_path}/ReactCommon/yoga"
  pod "React", :path => react_native_path, :subspecs => [
    'Core',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket'
  ]
end

在根目录下执行
pod install


关于报错
No podspec found for `Yoga` in `./node_modules/react-native/ReactCommon/yoga/Yoga.podspec`

上边的Podfile文件中没有添加  pod "Yoga", :path => "#{ react_native_path}/ReactCommon/yoga”,或者是该路劲不对

No podspec found for `React` in `../node_modules/react-native`

上边的Podfile文件中 pod "React", :path => react_native_path, :subspecs =>[ ];path可能不对

 类似资料: