使用場景
最新升級 Xcode 到最新版本 11.3诸典,執(zhí)行命令react-native run-ios會報(bào)錯
Found Xcode workspace taroDemo.xcworkspace
Could not find iPhone 6 simulator
網(wǎng)上無效方法
首先,你需要:
node_modules /反應(yīng)本地/本地CLI / runIOS / findMatchingSimulator.js
然后;
您需要更改此代碼
if (!version.startsWith('iOS') && !version.startsWith('tvOS'))
如下
if (version.indexOf('iOS') !== 0 && !version.includes('iOS')) { continue; }
最終解決方案
先說解決辦法
找到findMatchingSimulator.js
./node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
以下是修改后完整代碼
function findMatchingSimulator(simulators, simulatorName) {
if (!simulators.devices) {
return null;
}
const devices = simulators.devices;
var match;
for (let version in devices) {
console.log(" version in devices ");
console.log(version);
// 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;
}
for (let i in devices[version]) {
let simulator = devices[version][i];
// Skipping non-available simulator
if (simulator.isAvailable !== true) {
continue;
}
let booted = simulator.state === 'Booted';
if (booted && simulatorName === null) {
return {
udid: simulator.udid,
name: simulator.name,
booted,
version
};
}
if (simulator.name === simulatorName && !match) {
match = {
udid: simulator.udid,
name: simulator.name,
booted,
version
};
}
// Keeps track of the first available simulator for use if we can't find one above.
if (simulatorName === null && !match) {
match = {
udid: simulator.udid,
name: simulator.name,
booted,
version
};
}
}
}
if (match) {
return match;
}
return null;
}
module.exports = findMatchingSimulator;
分析
最關(guān)鍵的地方是添加下面兩行代碼
console.log(" version in devices ");
console.log(version);
添加后執(zhí)行react-native run-ios搂蜓,可以看到模擬器版本信息
productdeMacBook-Pro:taro-native-shell product$ react-native run-ios
Scanning folders for symlinks in /Users/product/Desktop/taro-native-shell/node_modules (15ms)
Found Xcode workspace taroDemo.xcworkspace
version in devices
com.apple.CoreSimulator.SimRuntime.iOS-9-2
version in devices
com.apple.CoreSimulator.SimRuntime.iOS-10-3
version in devices
com.apple.CoreSimulator.SimRuntime.tvOS-13-3
version in devices
com.apple.CoreSimulator.SimRuntime.iOS-13-3
version in devices
com.apple.CoreSimulator.SimRuntime.watchOS-6-1
version in devices
com.apple.CoreSimulator.SimRuntime.iOS-8-1
version in devices
com.apple.CoreSimulator.SimRuntime.iOS-9-3
version in devices
com.apple.CoreSimulator.SimRuntime.iOS-12-1
version in devices
com.apple.CoreSimulator.SimRuntime.iOS-10-0
以上可以看到模擬器的版本信息
敲黑板, 劃重點(diǎn)
可以看到打印的信息,模擬器版本信息為
com.apple.CoreSimulator.SimRuntime.iOS-9-2
到這你肯定發(fā)現(xiàn),上面修改代碼的地方了
對的網(wǎng)上找的大部分都是
if (!version.startsWith('iOS') && !version.startsWith('tvOS')){ continue; }
改成
if (version.indexOf('iOS') !== 0 && !version.includes('iOS')) { continue; }
打印后你會發(fā)現(xiàn)每次 xcode 版本不同模擬器也會不一樣圾另,所以修改后還是無效,我的 xcode 是 11.3雕沉,打印信息如上集乔,所以修改為
if (!version.startsWith('iOS') && !version.startsWith('tvOS')){ continue; }
改成
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')){ continue; }
還有一處判斷方法也需要修改
simulator.availability !== '(available)'
改成
if (simulator.isAvailable !== true)
以上就是解決辦法總結(jié),也是網(wǎng)上找了很多辦法坡椒,最后還是在GitHub Error: Could not find iPhone 6 simulator #21498 上找到的希望對大家有用吧扰路,開發(fā)不易,希望大家都好好珍惜這段時(shí)光倔叼。