I have a URLHandler that launches some application, the main code is as follows.
我有一个启动一些应用程序的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;
}
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?
由于此例程的目标是启动另一个应用程序,我想在启动应用程序后退出此URLHandler。我怎样才能做到这一点?
2 个解决方案
#1
18
-
You don't have to launch
open
usingNSTask
...open
just calls into Launch Services, some of whose functionality is directly available from NSWorkspace.您不必使用NSTask启动打开...只需调用Launch Services,其中一些功能可直接从NSWorkspace获得。
-
To quit, you just call
[[NSApplication sharedApplication] terminate:nil]
. SeeNSApplication
documentation.要退出,只需调用[[NSApplication sharedApplication] terminate:nil]。请参阅NSApplication文档。
#2
1
This has been answered here: Proper way to exit iPhone application? however you should also take a look at August's answer. Although it's not the accepted answer, it has been voted higher and it also follows Apple's set standards since Apple advises against force quitting iPhone applications.
这已在这里得到解答:退出iPhone应用程序的正确方法?不过你也应该看看八月的回答。虽然它不是公认的答案,但由于苹果公司建议不要强行退出iPhone应用程序,因此它已经被推高,并且也遵循了Apple的既定标准。
#1
18
-
You don't have to launch
open
usingNSTask
...open
just calls into Launch Services, some of whose functionality is directly available from NSWorkspace.您不必使用NSTask启动打开...只需调用Launch Services,其中一些功能可直接从NSWorkspace获得。
-
To quit, you just call
[[NSApplication sharedApplication] terminate:nil]
. SeeNSApplication
documentation.要退出,只需调用[[NSApplication sharedApplication] terminate:nil]。请参阅NSApplication文档。
#2
1
This has been answered here: Proper way to exit iPhone application? however you should also take a look at August's answer. Although it's not the accepted answer, it has been voted higher and it also follows Apple's set standards since Apple advises against force quitting iPhone applications.
这已在这里得到解答:退出iPhone应用程序的正确方法?不过你也应该看看八月的回答。虽然它不是公认的答案,但由于苹果公司建议不要强行退出iPhone应用程序,因此它已经被推高,并且也遵循了Apple的既定标准。