1??常用命令
1. 查看當前可用的所有設備/模擬器列表:
在終端中輸入
xcrun simctl list devices
2. iPhone模擬器啟動(下次啟動會默認使用最后一次選擇設備,直接啟動 react-native run-ios 即可):
react-native run-ios --simulator "iPhone 7 Plus”
3. 使用真機運行項目:
- 使用真機運行之前需要安裝一個軟件,打開終端輸入以下命令
npm i -g ios-deploy
安裝完成之后,輸入以下命令
react-native run-ios --device "'wo's iPhone X"
真機名字可以從Xcode的設備列表打開查看對應的名字或者手機->設置->關于手機查看設備名
(網上查到的但是現版本不存在)
注:這是一個react native的bug:需要將:node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js文件的: // Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc) if (!version.startsWith('iOS') && !version.startsWith('tvOS')) { continue; }修改成: // Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc) if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) { continue; }
react-native run-ios出錯,報找不到iPhone X模擬器最好直接yongXcode啟動吧,這命令查了好久沒解決。
2??可能報錯
2.1 Print: Entry, “:CFBundleIdentifier”, Does Not Exist
Installing build/Build/Products/Debug-iphonesimulator/awesome.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, “:CFBundleIdentifier”, Does Not Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/awesome.app/Info.plist
Print: Entry, “:CFBundleIdentifier”, Does Not Exist
解決方法 執行如下命令:
1. react-native upgrade
2. react-native run-ios
2.2 Unrecognized font family ‘Ionicons
在項目根目錄執行
1. npm link react-native-vector-icons
2. react-native link react-native-vector-icons
3. yarn add react-native-elements (or) npm i react-native-elements --save
2.3 Unable to resolve module ‘react-native-vector-icons/FontAwesome’
在項目根目錄執行
1. yarn add react-native-vector-icons
2. react-native start --reset-cache
2.4 用web storm 運行react-native 工程時,出錯:xcrun: error: unable to find utility “instruments”, not a developer tool or in PATH
解決方法:在 終端執行如下命令 sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
2.5 報錯 No bundle url present
解決辦法: 刪除項目文件下的build文件夾,再次執行 react-native run-ios
1. cd 目錄/ios
2. rm -r build
3. react-native run-ios
這個錯誤有時重新運行一遍就好了