ios 无法在模拟器中运行应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26396166/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 03:13:48  来源:igfitidea点击:

Unable to run app in simulator

iosxcodeios-simulator

提问by Fang-Pen Lin

Today, when I try to run my app in simulator, it simply tells me

今天,当我尝试在模拟器中运行我的应用程序时,它只是告诉我

Unable to run app in Simulator
An error was encountered while running
(Domain = NSPOSIXErrorDomain, Code = 22)

And the error dialog looks like this:

错误对话框如下所示:

Unable to run app in Simulator

无法在模拟器中运行应用程序

I've tried many things:

我尝试了很多东西:

  • Restart Xcode
  • Restart Simulator
  • Reboot
  • Reset content and settings of simulator
  • 重启Xcode
  • 重启模拟器
  • 重启
  • 重置模拟器的内容和设置

None of above works. And I looked into log, I found these are those records has something to do with this issue

以上都不起作用。我查看了日志,我发现这些记录与这个问题有关

2014/10/15 9:09:40.964 com.apple.CoreSimulator.CoreSimulatorService[979]: Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7f96c861d000 {NSLocalizedDescription=Unable to lookup in current state: Shutdown}

2014/10/15 9:09:40.964 Xcode[1983]: [MT] iPhoneSimulator: Unable to connect to "com.apple.instruments.deviceservice.lockdown" (Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7fcf6fc24190 {NSLocalizedDescription=Unable to lookup in current state: Shutdown})

2014/10/15 9:09:40.980 com.apple.CoreSimulator.CoreSimulatorService[979]: Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7f96c861d000 {NSLocalizedDescription=Unable to lookup in current state: Shutdown}

2014/10/15 9:09:42.351 launchd_sim[2047]: assertion failed: 13F34: libxpc.dylib + 29453 [75E30F22-514B-3A20-B82C-EDA43AF5C35C]: 0x8d

2014/10/15 9:09:42.362 com.apple.CoreSimulator.CoreSimulatorService[979]: Could not register service com.apple.coreservices.lsuseractivity.simulatorsupport: Failed to lookup com.apple.coreservices.lsuseractivity.simulatorsupport: 0x44e

2014/10/15 9:09:40.964 com.apple.CoreSimulator.CoreSimulatorService[979]:错误域=com.apple.CoreSimulator.SimError Code=146“无法在当前状态下查找:关闭” UserInfo=0x7f96c861d000 {NS无法在当前状态下查找:关机}

2014/10/15 9:09:40.964 Xcode[1983]:[MT] iPhoneSimulator:无法连接到“com.apple.instruments.deviceservice.lockdown”(错误域=com.apple.CoreSimulator.SimError Code=146”无法在当前状态下查找:Shutdown" UserInfo=0x7fcf6fc24190 {NSLocalizedDescription=在当前状态下无法查找:Shutdown})

2014/10/15 9:09:40.980 com.apple.CoreSimulator.CoreSimulatorService[979]:错误域=com.apple.CoreSimulator.SimError Code=146“无法在当前状态查找:关闭”UserInfo=0x7f96c861d000 {NS无法在当前状态下查找:关机}

2014/10/15 9:09:42.351 launchd_sim[2047]:断言失败:13F34:libxpc.dylib + 29453 [75E30F22-514B-3A20-B82C-EDA43AF5C35C]:0

2014/10/15 9:09:42.362 com.apple.CoreSimulator.CoreSimulatorService[979]: 无法注册服务 com.apple.coreservices.lsuseractivity.simulatorsupport: 无法查找 com.apple.coreservices.lsuseractivity.simulatorsupport: 0x44e

I also found some other people had the same issue here : https://gist.github.com/bdeshong/2dd90add09b7287a9a85

我还发现其他一些人也有同样的问题:https: //gist.github.com/bdeshong/2dd90add09b7287a9a85

No luck to find solution after Googling around.

谷歌搜索后没有找到解决方案的运气。

Here is my environment information

这是我的环境信息

  • OSX 10.9.5
  • Xcode 6.0.1
  • iOS Simulator 8.0 (550.1)
  • OSX 10.9.5
  • Xcode 6.0.1
  • iOS 模拟器 8.0 (550.1)

Any ideas?

有任何想法吗?

回答by Fang-Pen Lin

I found the root causes, and I also found the solution. First thing I've done is to ensure this has something to do with Xcode rather than a problem relative to the project itself. I tried to create a new project, and it works perfectly fine. So I assume that is caused by something in my project.

我找到了根本原因,我也找到了解决方案。我所做的第一件事是确保这与 Xcode 有关,而不是与项目本身相关的问题。我尝试创建一个新项目,它运行良好。所以我认为这是由我的项目中的某些东西引起的。

I actually added a resourcesreference folder to my project. So I think the problem has something to do with it. However, even I removed the folder from project, the problem is still there. In the end, it turns out, the resourcesfolder could live in

我实际上resources在我的项目中添加了一个参考文件夹。所以我认为这个问题与它有关。但是,即使我从项目中删除了文件夹,问题仍然存在。最后,事实证明,该resources文件夹可以存在

  • Built App folder
  • App folder in simulator
  • 内置应用文件夹
  • 模拟器中的应用程序文件夹

Since Xcode may simply copy and overwrite target App bundle folder, so the resourcesfolder may still there in the App bundle folder. So after removing the resourcesfolder, you need to

由于 Xcode 可能只是简单地复制和覆盖目标 App bundle 文件夹,因此该resources文件夹可能仍在 App bundle 文件夹中。所以删除resources文件夹后,你需要

  • Ensure the build is cleaned
  • Ensure the app in simulator is deleted
  • 确保构建已清理
  • 确保模拟器中的应用被删除

And for the reason the App cannot be launched correctly, that's because it appears resourcesis actually a reserved folder name in the bundle structure. By adding a folder named resourcesinto the bundle, somehow ruined the normal structure. To solve the problem, I changed the name from resourcesto app_data, or whatever it is, that all work.

并且由于应用程序无法正确启动的原因,那是因为它resources实际上是捆绑结构中的保留文件夹名称。通过resources在包中添加一个名为的文件夹,不知何故破坏了正常结构。为了解决这个问题,我将名称从 更改resourcesapp_data,或者不管它是什么,一切正常。

回答by alex

You are doing everything correct but Xcode and Swift are still in their early stages, means they are a little buggy right now. Maybe try restarting your Xcode and iOS Simulator once more.

你做的一切都是正确的,但 Xcode 和 Swift 仍处于早期阶段,这意味着它们现在有点问题。也许再次尝试重新启动 Xcode 和 iOS 模拟器。

回答by Guy

I got the exact same error. When browsing in my project info I inadvertently deleted the bundle identifier; hence the "ErrorDomain".

我得到了完全相同的错误。在浏览我的项目信息时,我无意中删除了包标识符;因此是“错误域”。

to correct, goto project data; info; set bundle identifier to whatever it was. it worked for me.

更正,转到项目数据;信息; 将捆绑标识符设置为任何内容。它对我有用。

回答by user3616535

I got the same. I just did force quit xcode and simulator then worked for me.

我得到了同样的。我只是强制退出 xcode 和模拟器然后为我工作。

回答by Alex Indigo

Check if you have proper permissions on your /private/tmpfolder, should be writable and executable for all users.

检查您的/private/tmp文件夹是否具有适当的权限,对于所有用户应该是可写和可执行的。

回答by Jeremy Huddleston Sequoia

This can happen for a couple of reasons:

发生这种情况的原因有两个:

  1. You quit the iOS Simulator.app while Instruments was trying to use it.
  2. You changed the booted device in the iOS Simulator.app while Instruments was trying to use another one.
  1. 当 Instruments 尝试使用它时,您退出了 iOS Simulator.app。
  2. 当 Instruments 尝试使用另一个设备时,您更改了 iOS Simulator.app 中启动的设备。

If neither of those is the case, take a look at ~/Library/Logs/CoreSimulator/*.log for more information that might help debugging and include it in your question.

如果这两种情况都不是,请查看 ~/Library/Logs/CoreSimulator/*.log 以获取可能有助于调试的更多信息并将其包含在您的问题中。

回答by Phillip Wheatley

Root cause in my case was slightly different. In the project file, the iOS deployment target was set to 8.0 for the test target and 8.1 for the main target. We were running Xcode 6.0.1 (6A317) with 8.0 simulators on our build servers, which all started failing after the main build target was set to 8.1.

在我的案例中,根本原因略有不同。在项目文件中,iOS 部署目标设置为测试目标的 8.0 和主目标的 8.1。我们在构建服务器上运行带有 8.0 模拟器的 Xcode 6.0.1 (6A317),在主构建目标设置为 8.1 后,所有模拟器都开始失败。

I'm not sure whether it was the fact that the target and tests were using different iOS deployment targets, or whether the 8.1 set in the project file conflicted with the 8.0 simulators, but it was this change which broke the simulators across several machines.

我不确定目标和测试是否使用不同的 iOS 部署目标,或者项目文件中设置的 8.1 是否与 8.0 模拟器冲突,但正是这种更改破坏了多台机器上的模拟器。

Unfortunately after setting the iOS Deployment Target back to 8.0 in the project, it still required a reinstall of Xcode (I also removed the ~/Library/Developer/Xcode directory) to return simulators to a functional state.

不幸的是,在项目中将 iOS 部署目标设置回 8.0 后,仍然需要重新安装 Xcode(我还删除了 ~/Library/Developer/Xcode 目录)以将模拟器恢复到功能状态。

回答by Balaji G

Clear all files in /Users/XXXXX/Library/Developer/CoreSimulator/Devices

清除/Users/XXXXX/Library/Developer/CoreSimulator/Devices 中的所有文件

Restart Xcode and Simulator.

重新启动 Xcode 和模拟器。

Now it will work.

现在它将起作用。