是否可以在 Xcode 中停止应用程序时关闭/退出 iOS 模拟器?我无法在 Xcode 或模拟器中找到设置来这样做。如果存在,将有助于加快开发过程。
最佳答案
要在构建停止时终止模拟器,您需要编译一个包含以下内容的可执行文件
#!/bin/sh
osascript -e 'tell app "iPhone Simulator" to quit'
保存此文件然后打开 Xcode 首选项的行为部分,在运行完成部分将您的脚本文件添加到运行部分。 希望这对您有用,但是这种方法似乎有点参差不齐,不幸的是,这是我能想到的最好方法! 祝你好运!
很遗憾您没有制作 OS X 应用程序,因为这样做非常容易。这部分无关紧要,但谁知道呢,您将来可能会用到它!
- (IBAction)KillSim:(id)sender {
NSLog (@"Sim Kill Begin");
NSDictionary* errorDict;
NSAppleEventDescriptor* returnDescriptor = NULL;
NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
@"tell application \"iPhone Simulator\" to quit"];
returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
[scriptObject release];
if (returnDescriptor != NULL)
{
// successful execution
if (kAENullEvent != [returnDescriptor descriptorType])
{
// script returned an AppleScript result
if (cAEList == [returnDescriptor descriptorType])
{
// result is a list of other descriptors
}
else
{
// coerce the result to the appropriate ObjC type
}
}
}
else
{
// no script result, handle error here
}
NSLog (@"Sim Killed End");
}
关于ios - 在 Xcode 中停止应用程序时自动关闭 iOS 模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9490238/