好久沒寫簡(jiǎn)書了 去年我接觸了react native 發(fā)現(xiàn)它很方便快速的完成雙平臺(tái)開發(fā),
這里我先簡(jiǎn)單說下在做rn中遇到的一些問題 之后會(huì)陸續(xù)寫更多
接手過一個(gè)老版本rn項(xiàng)目 當(dāng)時(shí)是打包傳過來的 當(dāng)運(yùn)行時(shí)發(fā)現(xiàn)了問題
首先是每次Xcode運(yùn)行都會(huì)提示我

這是說你的launchPackager.command沒有執(zhí)行權(quán)限
然后會(huì)報(bào)

類似這個(gè)錯(cuò)誤
解決方法是
在終端 輸入 $chmod 755 /Users/....../node_modules/react-native/packager/launchPackager.command 和 $ chmod 755 /Users/....../node_modules/react-native/local-cli/setup_env.sh
即可 (你的本機(jī)路徑)
另外 rn有時(shí)候會(huì)報(bào)一些你想不到的問題
按如下:
安裝 npm-check-updates 這個(gè)包:
npm i -g npm-check-updates在項(xiàng)目目錄下
rm -rf node_modules
ncu -u
npm install
這樣可以解決很多莫名其妙的 node 包依賴問題
有時(shí)你用Xcode跑工程時(shí) 可能會(huì)出現(xiàn)這個(gè)問題
Script-00DD1BFF1BD5951E006B06BC.sh: line 3: ../node_modules/react-native/packager/react-native-xcode.sh: No such file or directory
這是因?yàn)閞eact-native 低版本升級(jí)到0.49以上版本導(dǎo)致的
解決方法
1.打開 Xcode Build Phases > Bundle React Native code and images
2.修改export NODE_BINARY=node ../node_modules/react-native/packager/react-native-xcode.sh 為export NODE_BINARY=node ../node_modules/react-native/scripts/react-native-xcode.sh

老版本rn iOS工程里會(huì)這樣生成代碼
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"index.ios" withExtension:@"jsbundle"];
這樣如果后期 UI發(fā)生變化時(shí) ios是不會(huì)跟著變得
按新版本的寫 應(yīng)該這樣寫
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];