2013-05-28 203 views
0

我有一個打包應用程序,打開其他應用程序,我們稱之爲助手應用程序。此應用程序位於包裝應用程序資源文件夾內。如果「助手」應用程序關閉,關閉主應用程序

我想在助手應用程序關閉後關閉主應用程序。我怎樣才能做到這一點?

我也想知道,在助手打開後,如何退出包裝器應用程序。

+3

你開發OSX或iOS? –

+0

對不起,我忘了提及,我爲OSX開發。 – Silex

回答

2

您正在爲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 
    } 
} 
+0

謝謝你的詳細解答! – Silex

0

簡短的回答 - 你不能!

每個應用程序都以沙盒模式工作。你可以調用其他應用程序,但你失去了對你的控制(當然你可以使用AppDelegate標準方法來處理進入/返回前景/免費動作,但就是這樣)。

+0

感謝您的回答。然後我去接受我標記爲接受的帖子,它在啓動助手應用程序後退出包裝器應用程序。 – Silex

+0

正確....你沒有爲OSX開發的維度我認爲你想到了iOS。 – Kuba