一 安裝
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錯誤