一 安装
1. 安装
在你的项目根目录下运行以下命令:(根目录通常为带有package.json的)
npm install -g react-native-update-cli rnpm
npm install --save react-native-update
2. 手动和自动link
a. 如果项目为纯RN项目执行以下命令
react-native link react-native-update
b. 如果是RN植入到iOS原生项目,经测试link无用,用cocopods自动链接(重点,我本人就在这一步卡住了,如果不按照这个步骤会报错 'React/RCTDefines.h' file not found)
找到node_modules->react-native-update
touch react-native-update.podspec
在react-native-update.podspec这个文件中编辑
require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
Pod::Spec.new do |s|
s.name = "react-native-update"
s.version = package["version"]
s.summary = "hot update for react-native"
s.author = "author (https://github.com/reactnativecn)"
s.homepage = "https://github.com/reactnativecn/react-native-pushy"
s.license = "MIT"
s.platform = :ios, "7.0"
s.source = { :git => "https://github.com/reactnativecn/react-native-pushy.git", :tag => "#{s.version}" }
s.source_files = "ios/**/*.{h,m,c}"
s.libraries = "bz2"
s.dependency "React"
end
在Podfile中添加路径
pod 'react-native-update' , :path => './node_modules/react-native-update'
pod update
3. 配置Bundle URL(iOS)
4. 在工程target的Build Phases->Link Binary with Libraries中加入libz.tbd、libbz2.1.0.tbd
5. 工程中添加代码
#import "RCTHotUpdate.h"
#if DEBUG
// 原来的jsCodeLocation
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
#else
jsCodeLocation=[RCTHotUpdate bundleURL];
#endif
6. iOS的ATS例外配置
右键点击Info.plist,选择open as - source code
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>reactnative.cn</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
这些步骤完成可以解决添加pushy后 'React/RCTDefines.h' file not found错误