我有一个URLHandler,它启动了某个应用程序,主要代码如下。
@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退出。 我该如何做到这一点?
exit(0)
运行良好。 - prosseekexit(0)
。Cocoa 在退出前可能需要进行一些清理工作。我不确定 Cocoa 是否将这些清理函数注册到atexit
中,因此我建议您调用-[NSApplication terminate:]
。 - Yuji