我有一個打包應用程序,打開其他應用程序,我們稱之爲助手應用程序。此應用程序位於包裝應用程序資源文件夾內。如果「助手」應用程序關閉,關閉主應用程序
我想在助手應用程序關閉後關閉主應用程序。我怎樣才能做到這一點?
我也想知道,在助手打開後,如何退出包裝器應用程序。
我有一個打包應用程序,打開其他應用程序,我們稱之爲助手應用程序。此應用程序位於包裝應用程序資源文件夾內。如果「助手」應用程序關閉,關閉主應用程序
我想在助手應用程序關閉後關閉主應用程序。我怎樣才能做到這一點?
我也想知道,在助手打開後,如何退出包裝器應用程序。
您正在爲OSX(10.6及更高版本)開發嗎? 在這種情況下,使用NSRunningApplication來終止包裝應用程序。
@implementation AppDelegate // Helper Application delegate
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
NSArray *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.yourApplication.Launcher"];
if ([apps count])
[(NSRunningApplication *)[apps objectAtIndex:0] terminate];
}
@end
你還可以用NSWorkspace同步啓動您的助手:
- (void)launchHelper // Wrapper launch method
{
NSURL *helperURL = [[NSBundle mainBundle] URLForResource:@"Helper" withExtension:@"app"];
if (helperURL)
{
NSError *err = nil;
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:helprURL options:NSWorkspaceLaunchAllowingClassicStartup configuration:nil error:&err];
// here Helper 'main' have been called
}
}
謝謝你的詳細解答! – Silex
你開發OSX或iOS? –
對不起,我忘了提及,我爲OSX開發。 – Silex