@interface AppDelegate : NSObject <NSApplicationDelegate>
-(void)relaunchApp; //重启应用
@end
@interface AppDelegate ()
@property (nonatomic, assign) BOOL toRelaunch; //重启应用
@end
@implementation AppDelegate
-(void)applicationWillTerminate:(NSNotification *)notification{
if (self.toRelaunch) {
[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:kBundleId options:NSWorkspaceLaunchAsync | NSWorkspaceLaunchNewInstance additionalEventParamDescriptor:nil launchIdentifier:nil];
}
}
-(void)relaunchApp{
self.toRelaunch = YES;
[[NSApplication sharedApplication] terminate:nil];
}
@end