0

パッケージファイルを起動して、インストールが終了/終了するのを待ちたいです。その間、メインの呼び出し元アプリケーションは終了するまでロックする必要があります。

これまで私は以下を試しました...

- (IBAction)installDriver:(id)sender
{
    NSString *file = [[NSBundle mainBundle] pathForResource:@"ExamplePackage" ofType:@"pkg"];
    [[NSWorkspace sharedWorkspace] openFile:file];
    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(appDidEnd:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
}

- (void)appDidEnd:(NSNotification *)notification
{
    NSLog(@"app info: %@", [notification userInfo]);
}

問題は、アプリが閉じるたびにappDidEndが呼び出されることです。さらに、userinfoがinstaller.appを閉じるアプリとして報告するため、ExamplePackage.pkgが閉じられたものであるかどうかを検出できません。

私が達成しようとしていることのために何をしようとしているのかについてのアイデア....

4

1 に答える 1

0

NSTaskの存在を認識した後、解決策を見つけました。

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/open"];
[task setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle] pathForResource:@"MyPackageFile" ofType:@"pkg"], nil]];
[task launch];
[task waitUntilExit];

方法を知っていれば簡単です:)

于 2013-01-11T21:33:07.113 に答える