How to upgrade Mac OSX Application

╄→尐↘猪︶ㄣ 提交于 2020-01-06 07:08:53

问题


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.

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


回答1:


Sparkle does couple of things internally

  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];

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.

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)

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.

Here are samples.

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


来源:https://stackoverflow.com/questions/22012901/how-to-upgrade-mac-osx-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!