Based on the Sparkle source code, here’s a quick way to restart any application that includes the Sparkle framework.
NSString *launcherSource = [[NSBundle bundleForClass:[SUUpdater class]] pathForResource:@"relaunch" ofType:@""];
NSString *launcherTarget = [NSTemporaryDirectory() stringByAppendingPathComponent:[launcherSource lastPathComponent]];
NSString *appPath = [[NSBundle mainBundle] bundlePath];
NSString *processID = [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]];
[[NSFileManager defaultManager] removeItemAtPath:launcherTarget error:NULL];
[[NSFileManager defaultManager] copyItemAtPath:launcherSource toPath:launcherTarget error:NULL];
[NSTask launchedTaskWithLaunchPath:launcherTarget arguments:[NSArray arrayWithObjects:appPath, processID, nil]];
[NSApp terminate:sender];
If you’re not using Sparkle, here’s a complete implementation of this idea you may find helpful.
本文介绍了一种利用Sparkle框架实现Cocoa应用程序自我重启的方法。相较于传统的命令行辅助程序方案,这种方法更为简便。文章提供了具体的代码示例,演示了如何通过Sparkle框架内的资源来实现应用程序的平滑重启。

被折叠的 条评论
为什么被折叠?



