如何在Objective-C应用程序中退出? [英] How to quit itself in Objective-C application?

查看:326
本文介绍了如何在Objective-C应用程序中退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启动某些应用程序的URLHandler,主要代码如下.

I have a URLHandler that launches some application, the main code is as follows.

@implementation URLHandlerCommand

- (id)performDefaultImplementation {
    NSString *urlString = [self directParameter];

    NSLog(@"url :=: %@", urlString);

    NSTask *task;
    task = [[NSTask alloc] init];
    [task setLaunchPath: @"/usr/bin/open"];

    NSArray *arguments;
    arguments = [NSArray arrayWithObjects: @"-a", @"Path Finder.app", urlString, nil];
    [task setArguments: arguments];

    NSPipe *pipe;
    pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];

    NSFileHandle *file;
    file = [pipe fileHandleForReading];

    [task launch];

    return nil;
}

由于此例程的目标是启动另一个应用程序,因此我想在启动应用程序后退出此URLHandler.我该怎么办?

As the goal of this routine is to launch another application, I'd like to make this URLHandler quit after launching an App. How can I do that?

推荐答案

  1. 您不必使用NSTask启动open ... open只需调用

  1. You don't have to launch open using NSTask... open just calls into Launch Services, some of whose functionality is directly available from NSWorkspace.

要退出,只需致电[[NSApplication sharedApplication] terminate:nil].请参阅 NSApplication文档.

To quit, you just call [[NSApplication sharedApplication] terminate:nil]. See NSApplication documentation.

这篇关于如何在Objective-C应用程序中退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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