[英]Could not find iPhone 6 simulator after upgrade to Xcode 10
我更新到 Xcode 10,因为我这样做了,所以我无法使用命令react-native run-ios
在终端中运行模拟器。 我收到此错误:
找不到 iPhone 6 模拟器
当我转到 Xcode > Window > Devices and Simulator 时,模拟器就在那里,当我执行xcrun simctl list devices
我还会看到模拟器列表。
我可以使用react-native run-ios --device
和 Xcode 在我的手机上运行该应用程序,并且我尝试了多个应用程序,因此它不是应用程序。
当我转到 Xcode > Preferences > Locations 时,在命令行工具中选择了 Xcode 10.0 (10A255)。
我尝试重新启动计算机,以及删除并重新安装 Xcode。
任何想法可能是什么?
这是我的设置:
我去了 node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
我已经替换了:
if (version.indexOf('iOS') !== 0 )
和
if (!version.includes("iOS" ))
和
if (simulator.availability !== '(available)')
和
if (simulator.isAvailable !== true)
我有类似的问题。 React Native - 0.52.3,XCode - 10.2 beta 2
function findMatchingSimulator(simulators, simulatorName) {
if (!simulators.devices) {
return null;
}
const devices = simulators.devices;
var match;
for (let version in devices) {
// Making sure the version of the simulator is an iOS (Removes Apple Watch, etc)
if (!version.includes('iOS')) {
continue;
}
[...]
}
}
打开文件: node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
检查您的设备版本是否正确,例如:在第 29 行console.log(version)
将其与第 30 行中的条件进行比较: if (version.indexOf('iOS') !== 0) {
我有这样的版本列表:
com.apple.CoreSimulator.SimRuntime.watchOS-5-0 -1
com.apple.CoreSimulator.SimRuntime.tvOS-12-1 -1
com.apple.CoreSimulator.SimRuntime.tvOS-12-2 -1
在这种情况下,我的任何版本都不会返回 true ......如果你有它
!version.includes('iOS')
替换version.indexOf('iOS') !== 0
,它为我解决了这个问题。该错误已在react-native
修复,因此您可以更新 package.json 中的包:
npm install -g npm-check-updates
ncu -u react-native
npm install
找到了解决我的问题的东西。
您需要进入 react-native 节点模块中的local-cli/runIOS/findMatchingSimulator.js
并将第 37 行更改为
if (
simulator.availability !== '(available)' &&
simulator.isAvailable !== 'YES'
) {`
有关解决方案和 react-native github 问题的更多信息:
https://github.com/facebook/react-native/commit/1031872
https://github.com/facebook/react-native/issues/21571
我只是想与你们分享我是如何修复它的,也许它可以帮助某人。
编辑此文件: node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
改变:
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
continue;
}
到:
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS')
&& !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
continue;
}
它对我有用。
我使用console.log(version)来查看我从变量version 中得到的内容,并且该值不符合预期。
可以通过修复下面的文件来解决。
/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
替换这一行
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
和
if (!version.includes('iOS') && !version.includes('tvOS')) {
使用带有XCode 10 的react-native 版本0.55.3
我必须做两个更改才能react-native run-ios
。
在node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
:
@martin-leroux 描述的变化:
改变
// Skipping non-available simulator if (simulator.availability !== true) {
到
// Skipping non-available simulator if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) {`
更改@samernady 提到的行:
改变
// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc) if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
到
// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc) if (!version.includes('iOS') && !version.startsWith('tvOS')) {
我有一个 findMatchingSimulator.js 的自我重构版本。 如果将来有人仍然面临此问题并且上述解决方案无法解决您的问题,只需使用以下代码覆盖 ...node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js 中的 findMatchingSimulator-Method :
function findMatchingSimulator(simulators, simulatorName) {
if (!simulators.devices) {
return null;
}
const devices = simulators.devices;
var match = null;
for(let version in devices){
//Skip WatchOS
if(!version.includes("tvOS") && !version.includes("iOS")){
continue;
}
for(let d in devices[version]){
var currentDevice = devices[version][d];
if(!currentDevice.isAvailable){
continue;
}
if(currentDevice.state === "Booted" ){
let booted = currentDevice.state === "Booted";
if(currentDevice.name === simulatorName ){
return {
udid: currentDevice.udid,
name: currentDevice.name,
booted,
version,
};
}else if(!match){
//keep track of first available & bootable device
match = {
udid: currentDevice.udid,
name: currentDevice.name,
booted,
version,
};
}
}
}
}
if (match) {
return match;
}
return null;
}
}
编辑:此代码将选择一个已经打开的模拟器,您仍然可以使用 --simulator="NAME" 参数。
一种对我有用的选择
使用检查安装在您的 mac 中的模拟器列表
xcrun simctl list --json devices
在模拟器列表上,选择任何模拟器名称并像这样运行
react-native run-ios --simulator 'iPhone 6s'
希望这对你有用
转到 node_modules/react-native/local-cli/runIOS/ 并在 findMatchingSimulator.js 中将第 30 行替换为
if (version.indexOf('com.apple.CoreSimulator.SimRuntime.iOS') !== 0) {
xcrun simctl list --json devices
自己编辑node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
。 确保findMatchingSimulator
函数返回一个match
对象,如
{
udid: simulator.udid,
name: simulator.name,
version
}
我必须做的是:
npm install -g npm
从 package.json "react": "XXXXXXXX", "react-native": "YYYYYYYY", 中删除这些行
然后运行 npm install --save react-native react
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.