且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何升级Mac OSX应用程序

更新时间:2023-10-20 18:22:16

Sparkle在内部完成了几件事

Sparkle does couple of things internally

  1. 它会检查服务器上是否有可用的新版本.
  2. 如果可用,请下载并升级现有应用,然后 重新启动相同的应用程序.
  1. It checks for the new version available on server or not.
  2. If it's available then download it and upgrade the existing app and relaunch the same application.

我对第二部分更感兴趣,所以这是它的工作方式.

I'm more of interested in 2nd part, so here is how it does it.

NSString *installerPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.installer"];
    installerPath = [installerPath stringByAppendingString:@"/Contents/MacOS/Installer"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:installerPath])
    {
        error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]];
        result = NO;
    }
    NSTask *installer = [NSTask launchedTaskWithLaunchPath:installerPath arguments:[NSArray arrayWithObjects:path, nil]];
    [installer waitUntilExit];

现在在这里您可以看到它找到Installer.app,并将pkg作为命令行参数传递给它.

Now here you can see that it finds the Installer.app and pass the pkg as command line argument to it.

安装程序应用程序负责升级应用程序.

Installer app takes care of upgrading the app.

还有另一种使用终端命令行可执行文件静默执行此操作的方法/usr/sbin/installer-有关更多信息,请访问Wiki-安装程序(Mac OS X)

There is one more way of doing it silently using terminal command line executable /usr/sbin/installer - More information is on wiki - Installer(Mac OS X)

如果您不想启动安装程序GUI,则可以使用上述命令并提供pkg文件路径和卷信息以进行安装.

If you do not want to launch the Installer GUI then you can use above command and give pkg file path and volume information for installation.

这是样本.

installer -pkg InstallMe.pkg -target CurrentUserHomeDirectory
installer -pkg InstallMe.pkg -target '/Volumes/Macintosh HD2' -lang ja
installer -volinfo -pkg InstallMe.pkg
installer -pkginfo -pkg InstallMe.pkg
installer -query RestartAction -pkg InstallMe.pkg
installer -pkg InstallMe.pkg -target / -showChoices