[关闭]
@Rookie 2020-08-03T12:30:21.000000Z 字数 1657 阅读 1430

iOS 项目添加 React Native

reactnative


package.json 中的版本号

  1. {
  2. "name": "testReactNative",
  3. "version": "0.0.1",
  4. "private": true,
  5. "scripts": {
  6. "start": "node node_modules/react-native/local-cli/cli.js start"
  7. },
  8. "dependencies": {
  9. "react": "16.0.0-alpha.12",
  10. "react-native": "0.45.1"
  11. }
  12. }

需要注意 react版本号 , 和 react-native 版本号
这里需要注意"react-native": "0.45.1", "react": "16.0.0-alpha.12", , 可能会报错,
修改成: "react": "16.0.0-alpha.6",
"react-native": "0.46.1"
有待测试

podfile 中需要添加 yoga

[!] Unable to find a specification for `Yoga (= 0.42.3.React)` depended upon by `React/Core`
  1. # Your 'node_modules' directory is probably in the root of your project,
  2. # but if not, adjust the `:path` accordingly
  3. pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  4. pod 'React', :path => '../node_modules/react-native', :subspecs => [
  5. 'Core',
  6. 'RCTText',
  7. 'RCTNetwork',
  8. 'RCTWebSocket', # needed for debugging
  9. # Add any other subspecs you want to use in your project
  10. ]
  11. pod 'Yoga', :path =>

注意配配置 podfiel 的路径问题

pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

JavaScriptCore.h file not found 问题

pod请升级到1.2.1以上 ,
这里也可能是 react native 版本问题

  1. 更新gemsudo gem update --system
  2. 删除gem源:gem sources --remove https://ruby.taobao.org/
  3. 修改gem源:gem sources -a https://gems.ruby-china.org
  4. 查看gem源是否是最新的:gem sources -l
  5. 升级cocoapodssudo gem install -n /usr/local/bin cocoapods --pre
  6. 查看升级后的cocoapods版本:pod --version
  7. 卸载:sudo gem uninstall cocoapods
  8. 安装:sudo gem install cocoapods
  9. 安装特定版本:sudo gem install cocoapods -v 0.35.0

问题地址

设置允许Http请求:

直接运行项目会报Could not connect to development server错误
解决方式:打开info.plist文件,添加下面配置即可:
如果有在 appdelegate崩溃处崩溃的, 可能也是因为没有允许 http 请求

  1. <key>NSAppTransportSecurity</key>
  2. <dict>
  3. <key>NSExceptionDomains</key>
  4. <dict>
  5. <key>localhost</key>
  6. <dict>
  7. <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
  8. <true/>
  9. </dict>
  10. </dict>
  11. </dict>

帮助地址

官方说明文档
简书中文 - React Native 集成到原生项目(iOS)

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注