升级到 Xcode 10 后找不到 iPhone 6 模拟器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52783369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not find iPhone 6 simulator after upgrade to Xcode 10
提问by Martin Leroux
I updated to Xcode 10 and since I did that, I can't run the simulator in terminal with the command react-native run-ios
. I get this error:
我更新到 Xcode 10,因为我这样做了,所以我无法使用命令在终端中运行模拟器react-native run-ios
。我收到此错误:
Could not find iPhone 6 simulator
找不到 iPhone 6 模拟器
When I go to Xcode > Window > Devices and Simulator the simulator is there and when I do xcrun simctl list devices
I also see the list of simulator.
当我转到 Xcode > Window > Devices and Simulator 时,模拟器就在那里,当我这样做时,xcrun simctl list devices
我还会看到模拟器列表。
I can run the app on my phone with react-native run-ios --device
and from Xcode, and I tried with multiple apps so it's not the app.
我可以使用react-native run-ios --device
Xcode 和从 Xcode在我的手机上运行该应用程序,并且我尝试了多个应用程序,因此它不是应用程序。
When I go to Xcode > Preferences > Locations, Xcode 10.0 (10A255) is selected at Command Line Tools.
当我转到 Xcode > Preferences > Locations 时,在命令行工具中选择了 Xcode 10.0 (10A255)。
I tried restarting the computer, as well as deleting and re-installing Xcode.
我尝试重新启动计算机,以及删除并重新安装 Xcode。
Any ideas what it could be?
任何想法可能是什么?
Here is my setup:
这是我的设置:
- MacOs High Sierra 10.13.6
- Xcode Version 10.0
- react-native-cli: 2.0.1
- react-native: 0.57.1
- MacOs High Sierra 10.13.6
- Xcode 10.0 版
- 反应原生cli:2.0.1
- 反应原生:0.57.1
回答by samernady
I went to node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
我去了 node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
And i've replaced:
我已经替换了:
if (version.indexOf('iOS') !== 0 )
if (version.indexOf('iOS') !== 0 )
with
和
if (!version.includes("iOS" ))
if (!version.includes("iOS" ))
And
和
if (simulator.availability !== '(available)')
if (simulator.availability !== '(available)')
with
和
if (simulator.isAvailable !== true)
if (simulator.isAvailable !== true)
回答by Damian
I had similar issue. React Native - 0.52.3, XCode - 10.2 beta 2
我有类似的问题。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;
}
[...]
}
}
Open file:
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
Check if your device version is correct, e.g: in line 29
console.log(version)
Compare it with condition in line 30:
if (version.indexOf('iOS') !== 0) {
打开文件:
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
检查您的设备版本是否正确,例如:在第 29 行
console.log(version)
将其与第 30 行中的条件进行比较:
if (version.indexOf('iOS') !== 0) {
I had versions list like this:
我有这样的版本列表:
com.apple.CoreSimulator.SimRuntime.watchOS-5-0 -1
com.apple.CoreSimulator.SimRuntime.tvOS-12-1 -1
com.apple.CoreSimulator.SimRuntime.tvOS-12-2 -1
Any of my versions doesn't return true in this condition... If you have it
在这种情况下,我的任何版本都不会返回 true ......如果你有它
- Replace
version.indexOf('iOS') !== 0
with!version.includes('iOS')
and it solve this issue for me.
- 替换
version.indexOf('iOS') !== 0
为!version.includes('iOS')
它为我解决了这个问题。
回答by Danny Sullivan
The bug has been fixed in react-native
so you can update the package in the package.json:
该错误已被修复,react-native
因此您可以更新 package.json 中的包:
npm install -g npm-check-updates
ncu -u react-native
npm install
回答by Martin Leroux
Found something that resolved my problem.
You need to go in local-cli/runIOS/findMatchingSimulator.js
in react-native node module and change line 37 for
找到了解决我的问题的东西。
您需要进入local-cli/runIOS/findMatchingSimulator.js
react-native node 模块并更改第 37 行
if (
simulator.availability !== '(available)' &&
simulator.isAvailable !== 'YES'
) {`
More info on the solution and the problem on react-native github :
https://github.com/facebook/react-native/commit/1031872
https://github.com/facebook/react-native/issues/21571
有关解决方案和 react-native github 问题的更多信息:
https: //github.com/facebook/react-native/commit/1031872
https://github.com/facebook/react-native/issues/21571
回答by R. Calhau
I just want to share with you guys how I fixed it, maybe it can help someone.
我只是想与你们分享我是如何修复它的,也许它可以帮助某人。
Edit this file:node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
编辑此文件:node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
Change:
改变:
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
continue;
}
To:
到:
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS')
&& !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
continue;
}
It worked for me.
它对我有用。
I used console.log(version)to see what I got from the variable versionand the value wasn't expected as it should be.
我使用了console.log(version)来查看我从变量version 中得到的内容,并且该值不符合预期。
回答by Padam Prajapati
it can be solved to fix the file below.
可以通过修复下面的文件来解决。
/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
replace this line
替换这一行
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
with
和
if (!version.includes('iOS') && !version.includes('tvOS')) {
回答by Andru
Using react-native version 0.55.3
with XCode 10I had to do twochanges to get react-native run-ios
running.
0.55.3
在XCode 10 中使用 react-native 版本我必须做两个更改才能react-native run-ios
运行。
Inside node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
:
内部node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
:
The change as described by @martin-leroux :
Change
// Skipping non-available simulator if (simulator.availability !== true) {
to
// Skipping non-available simulator if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) {`
Change the line mentioned by @samernady :
Change
// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc) if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
to
// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc) if (!version.includes('iOS') && !version.startsWith('tvOS')) {
@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')) {
回答by Sercan Samet Savran
I have a self-refactored version of findMatchingSimulator.js. If someone in the future still facing this issue and the solutions mentioned above couldn't solve your problem, just overwrite the findMatchingSimulator-Method in ...node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js with following code:
我有一个 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;
}
}
EDIT: This code will choose an already opened simulator and you're still good to go with the --simulator="NAME" parameter.
编辑:此代码将选择一个已经打开的模拟器,您仍然可以使用 --simulator="NAME" 参数。
回答by bowencool
xcrun simctl list --json devices
Edit node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
yourself.
Ensure that the findMatchingSimulator
function returns an match
object like
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
自己编辑。确保findMatchingSimulator
函数返回一个match
对象,如
{
udid: simulator.udid,
name: simulator.name,
version
}
回答by Robert Alvarez
Go to node_modules/react-native/local-cli/runIOS/ and in findMatchingSimulator.js replace line 30 with
转到 node_modules/react-native/local-cli/runIOS/ 并在 findMatchingSimulator.js 中将第 30 行替换为
if (version.indexOf('com.apple.CoreSimulator.SimRuntime.iOS') !== 0) {