如何在Objective-C应用程序中退出? [英] How to quit itself in Objective-C application?
问题描述
我有一个启动某些应用程序的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?
推荐答案
-
您不必使用
NSTask
启动open
...open
只需调用 NSWorkspace .
You don't have to launch
open
usingNSTask
...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屋!