如何升级Mac OSX应用程序 [英] How to upgrade Mac OSX Application

查看:152
本文介绍了如何升级Mac OSX应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在客户端上工作.我们有一个守护程序正在运行,该守护程序将检查服务器上新版本的可用性,并在可用时下载新的.dmg文件.

I'm working on client side. We have a daemon running which checks for new version availability on server and whenever it's available it downloads the new .dmg file.

现在,我想在不显示安装窗口的情况下以静默方式升级现有应用程序.

Now I wanted to upgrade the existing application silently without showing the installation window.

我想知道自动升级任何Mac osx应用程序的方法.

I wanted to know what are the ways to auto upgrade any mac osx application.

推荐答案

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

这篇关于如何升级Mac OSX应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆