问题
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
- It checks for the new version available on server or not.
- 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