1、React Native-Pushy熱更新問題

一 安裝

1. 安裝

在你的項目根目錄下運行以下命令:(根目錄通常為帶有package.json的)

npm install -g react-native-update-cli rnpm

npm install --save react-native-update

2. 手動和自動link

a. 如果項目為純RN項目執(zhí)行以下命令

react-native link react-native-update

b. 如果是RN植入到iOS原生項目,經(jīng)測試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錯誤

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容