很高兴在 F8 2015 上看到 Facebook 开源 React Native。虽然他们提供react-native-cli
生成一个空的 React Native 项目,但我仍然不知道如何将 React Native 集成到我当前使用 Xcode 工作区和 CocoaPods 的项目中。
如何将 React Native 集成到现有的 iOS 项目中
您可以查看此演示: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
安装命令行工具。
然后进入你的Xcode工程目录,创建package.json
文件。内容是这样的:
然后你npm install
在终端node_modules
中运行pod init
。Podfile
稍后你会找到一个目录,下一步是运行。将创建。所以只需像流动一样打开和配置它
你应该注意你在 Podfile 中配置的 React 路径。
然后运行pod install
。您将获得工作区。
您还需要一个服务器或离线包,请查看此
https://facebook.github.io/react-native/docs/running-on-device-ios.html
https://github.com/facebook/react-native/issues/240
之后你可能会遇到一些问题:
1.命名冲突检测:
https://github.com/facebook/react-native/issues/3440
2.不适用于ios(App Extension).....
在 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
希望它有帮助:)
React Native 可作为 CocoaPod 使用,并作为 React Native 的一部分分发(node_modules
通过 npm 安装在内部)。
与现有应用程序集成非常容易,您只需RCTRootView
在视图层次结构中添加一个任意位置的实例,您的 React Native 应用程序就会在其中运行。请参阅本指南。
关于如何在现有项目中开始使用 React Native 的完整分步指南在这里:https : //facebook.github.io/react-native/docs/integration-with-existing-apps.html