在Xcode中停止应用程序时自动关闭iOS模拟器 [英] Automatically close iOS Simulator when application is stopped in Xcode

查看:621
本文介绍了在Xcode中停止应用程序时自动关闭iOS模拟器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to have the iOS Simulator close/quit whenever an application is stopped in Xcode? I haven't been able to find a setting in Xcode or in Simulator to do so. It would help speed up the development process if it exists.

推荐答案

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

To kill the simulator when your build is stopped, you will need to compile an executable file including the following

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

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

Save this file then open the behaviors section of Xcode preferences, in the run completes section add your script file to the run section. hopefully this will work for you, however this method seems to be a little spotty and is unfortunately the best way I've been able to come up with! Good luck!

这是太糟糕了,你没有制作OS X应用程序,因为这样做非常容易。这部分是无关紧要的,但谁知道,你将来可以使用它!

It's too bad that you're not making a OS X app because then doing this is extremely easy. This part is irrelevant but who knows, you may be able to use it in the future!

- (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");


}

这篇关于在Xcode中停止应用程序时自动关闭iOS模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆