標籤:
原版地址,這裡。中文翻譯版,這裡。
這裡整理下遇到的問題
1、指定root入參數未生效,表現形式:無法擷取index.ios.boundle檔案。
解決方案:其中文檔命令
JS_DIR=`pwd`/ReactComponent; cd Pods/React; npm run start -- --root $JS_DIR
無法正確的設定 root 地址,跟蹤了一下啟動調用版本,最終是調用../react-native/packager/packager.js 。故將啟動方式更改為
JS_DIR=`pwd`/ReactComponent; cd ../react-native/packager; node packager.js --root $JS_DIR
(1)保證執行指令碼的路徑必須在項目的跟路徑。
(2)保證根據cd命令進入到react-native的packager路徑下。
(3)出現問題後要根據自己項目的結構特點去修改指令碼,這是一個開發最基本的能力。
2、pods依賴問題。表現形式:無法再項目使用對應的基本類,在podlib中未正常產生libReact,或者項目出現 RCTRootView not fount。
解決方案:podfile中的正確配置
#React now version :0.11.0-rcpod ‘React‘, :path => ‘./react-native‘, :subspecs => [ ‘Core‘, ‘ART‘, ‘RCTActionSheet‘, ‘RCTAdSupport‘, ‘RCTGeolocation‘, ‘RCTImage‘, ‘RCTNetwork‘, ‘RCTPushNotification‘, ‘RCTSettings‘, ‘RCTText‘, ‘RCTVibration‘, ‘RCTWebSocket‘, ‘RCTLinkingIOS‘,]#需要的模組依賴進來便可,這裡是為了舉例子,列舉所有的模組
其中需要注意 :path => ‘./react-native‘ 該路徑對應的是你的podfile的相對路徑,可以在本地將官網的react-native在pod制定local依賴,一般是在zip包解壓下的../node_modules/react-native (可以根據官網下載的最新版本,example中找到該檔案夾)
其中pod install 過慢的問題解決方案:pod install --verbose --no-repo-update 。
其中無法正常下載pod install的解決方案(or更新最新的CocoaPods version: 0.39.0 查看方法 pod --version):
gem sources --remove https://rubygems.org/gem sources -a gem sources -l #注意 taobao 是 https ;gem如果版本太老可以更新:sudo gem update --system ;更新pod repo:pod repo update
查看CocoaPods 當前 repo中 react-native的版本
pod search React #目前的最新版本:0.11.0-rc #Versions: 0.11.0-rc, 0.10.0, 0.10.0-rc, 0.9.0, 0.9.0-rc, 0.8.0, 0.8.0-rc.2, 0.8.0-rc, 0.7.1, 0.7.0-rc.2, 0.6.0, 0.6.0-rc, 0.5.0, 0.4.4, 0.4.3, 0.4.2,# 0.4.1, 0.4.0, 0.3.11, 0.3.8, 0.3.4, 0.3.3, 0.3.2, 0.3.1, 0.3.0, 0.2.1, 0.2.0,# 0.1.0 [master repo]
3、服務端擷取bundle方式:
NSString *urlString = @" NSURL *jsCodeLocation = [NSURL URLWithString:urlString]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"DemoView" initialProperties:nil launchOptions:nil];
4、根據服務端offLine版本擷取bundle方式:
NSURL *jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"DemoView" withExtension:@"jsbundle"]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"DemoView" initialProperties:nil launchOptions:nil];
5、根據服務端產生bundle方式:
curl ‘http://localhost:8081/demo/DemoView.ios.bundle?platform=ios‘ -o DemoView.jsbundle
其他問題後續慢慢迭代整理。
現有的iOS項目整合ReactNative的記錄文檔