ios - 在 Xcode 中停止应用程序时自动关闭 iOS 模拟器

标签 ios xcode ios-simulator

是否可以在 Xcode 中停止应用程序时关闭/退出 iOS 模拟器?我无法在 Xcode 或模拟器中找到设置来这样做。如果存在,将有助于加快开发过程。

最佳答案

要在构建停止时终止模拟器,您需要编译一个包含以下内容的可执行文件

#!/bin/sh
osascript -e 'tell app "iPhone Simulator" to quit'

保存此文件然后打开 Xcode 首选项的行为部分,在运行完成部分将您的脚本文件添加到运行部分。 希望这对您有用,但是这种方法似乎有点参差不齐,不幸的是,这是我能想到的最好方法! 祝你好运! enter image description here

很遗憾您没有制作 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/

相关文章:

ios - MPMusicPlayerController 没有响应接近 1 的 currentPlaybackRate

iphone - 您能否要求 iPhone 3G(或更新版本)具有build设置?

64-bit - Xcode 5 在运行 64 位单元测试时显示 "Simulator in Use"

ios - 为什么 iOS 模拟器只显示一个空白 View /窗口?

ios - 如何将框架项目添加到主项目中并从主项目配置框架项目的设置

iPhone/iPad 和 iTunesArtwork

iphone - 当显示 Default.png 时,在启动期间在哪里更改状态栏的颜色

xcode - Gitlab - Xcode 无法连接远程存储库

ios - 在导航 Controller 中的 View 之间跳转

macos - Visual Studio 中的 Apache Cordova 无法连接 Mac(远程构建服务器)