現有的iOS項目整合ReactNative的記錄文檔

來源:互聯網
上載者:User

標籤:

原版地址,這裡。中文翻譯版,這裡。

這裡整理下遇到的問題

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的記錄文檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.