Cocoa コードからアプリケーションを (強制的ではなく) プログラムで終了する必要があります。
実際には、次のようになります。
-(BOOL) terminateAppWithBundle:(NSString*)bundle {
NSArray* array = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundle];
if ([array count] > 0){
NSRunningApplication* app = (NSRunningApplication*)[array objectAtIndex:0];
[array makeObjectsPerformSelector:@selector(terminate)];
float time = 0;
while (!app.isTerminated){
[NSThread sleepForTimeInterval:0.2];
time += 0.2;
if (time >= 15){
return NO;
}
}
}
return YES;
}
非常にうまく機能します...ただし、Snow Leopard と Lion のみです。
Leopard (サポートしたい) では、起動時にアプリケーションがクラッシュし、次のエラー メッセージが表示されます。
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _OBJC_CLASS_$_NSRunningApplication
NSRunningApplication が 10.5 SDK の一部ではないためだと思います...そのクラスを使用せずにどうすれば同じことができますか?