如何将 React Native 集成到现有的 iOS 项目中
How to integrate React Native to existing iOS project
很高兴看到 Facebook 在 F8 2015 上开源 React Native。虽然他们提供 react-native-cli
生成一个空的 React Native 项目,但我仍然不知道如何将 React Native 集成到我当前的项目中使用 Xcode 工作区和 CocoaPods。
React Native 可用作 CocoaPod 并作为 React Native 的一部分分发(在 node_modules
中通过 npm 安装)。
与现有应用程序集成非常简单,您只需在视图层次结构中的任意位置添加一个 RCTRootView
实例,您的 React Native 应用程序就会 运行 在其中。参见 this guide。
有关如何在现有项目中开始使用 React Native 的完整分步指南,请参见此处:
https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
您可以查看此演示:
https://github.com/dsibiski/react-native-hybrid-app-examples
在你开始使用react native之前,你应该阅读他们的文档流:
http://facebook.github.io/react-native/docs/getting-started.html
那么我们应该 运行 npm install -g react-native-cli
安装命令行工具。
下一步是安装 cocoapods。
然后进入你的Xcode项目目录,创建package.json
file.The内容如下:
然后你运行npm install
在terminal.After一会儿你会发现一个目录node_modules
下一步是 运行 pod init
。将创建 Podfile
。所以就像流动一样打开并配置它
那么你的 Podfile 就会像这样
You should pay attention to the React path you have configured in Podfile.
然后运行pod install
。您将获得工作区。
您还需要服务器或离线包,查看此
https://facebook.github.io/react-native/docs/running-on-device-ios.html
https://github.com/facebook/react-native/issues/240
之后您可能遇到的一些问题:
1.Naming 检测到碰撞:
https://github.com/facebook/react-native/issues/3440
2.Not 在 ios(应用程序扩展)上可用......
在 Podfile 中添加代码
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
希望对您有所帮助:)
很高兴看到 Facebook 在 F8 2015 上开源 React Native。虽然他们提供 react-native-cli
生成一个空的 React Native 项目,但我仍然不知道如何将 React Native 集成到我当前的项目中使用 Xcode 工作区和 CocoaPods。
React Native 可用作 CocoaPod 并作为 React Native 的一部分分发(在 node_modules
中通过 npm 安装)。
与现有应用程序集成非常简单,您只需在视图层次结构中的任意位置添加一个 RCTRootView
实例,您的 React Native 应用程序就会 运行 在其中。参见 this guide。
有关如何在现有项目中开始使用 React Native 的完整分步指南,请参见此处: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
您可以查看此演示: https://github.com/dsibiski/react-native-hybrid-app-examples
在你开始使用react native之前,你应该阅读他们的文档流: http://facebook.github.io/react-native/docs/getting-started.html
npm install -g react-native-cli
安装命令行工具。
下一步是安装 cocoapods。
然后进入你的Xcode项目目录,创建package.json
file.The内容如下:
然后你运行npm install
在terminal.After一会儿你会发现一个目录node_modules
下一步是 运行 pod init
。将创建 Podfile
。所以就像流动一样打开并配置它
那么你的 Podfile 就会像这样
You should pay attention to the React path you have configured in Podfile.
然后运行pod install
。您将获得工作区。
您还需要服务器或离线包,查看此
https://facebook.github.io/react-native/docs/running-on-device-ios.html
https://github.com/facebook/react-native/issues/240
之后您可能遇到的一些问题:
1.Naming 检测到碰撞:
https://github.com/facebook/react-native/issues/3440
2.Not 在 ios(应用程序扩展)上可用......
在 Podfile 中添加代码
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
希望对您有所帮助:)