可以将下面的代码放置于app delegate当中,然后通过tagAppRelaunch来控制app关闭时是直接关闭还是关闭再重新打开。你的app的BundleIdentifier可以在project summary中找到,默认值类似于“com.xxx.appname”。tagAppRelaunch的值可以在程序初始化时设置为NO。
- (void)applicationWillTerminate:(NSNotification *)notification{
if (tagAppRelaunch) {
[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:@"你的app的BundleIdentifier" options:NSWorkspaceLaunchAsync | NSWorkspaceLaunchNewInstance additionalEventParamDescriptor:nil launchIdentifier:NULL];
}
}
然后可以如下进行重启
tagAppRelaunch = YES;
[NSApp terminate:self];