在你Distribution.xml代碼,添加這個功能:
function dontDowngrade(prefix) {
if (typeof(my.result) != 'undefined') my.result.message = system.localizedString('ERROR_2');
var bundle = system.files.bundleAtPath(prefix + '/Applications/YOURAPPNAMEHERE');
if (!bundle) {
return true;
}
var bundleKeyValue = bundle['CFBundleShortVersionString'];
if (!bundleKeyValue) {
return true;
}
if (system.compareVersions(bundleKeyValue, '$packageVersion') > 0) {
return false;
}
return true;
}
錯誤字符串ERROR_2是Localizable.strings:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ERROR_0</key>
<string>This update requires Mac OS X version %@ or later.</string>
<key>ERROR_1</key>
<string>This software is not supported on your system.</string>
<key>ERROR_2</key>
<string>A newer version of this software is already installed. </string>
<key>SU_TITLE</key>
<string>YOURAPPNAMEHERE</string>
</dict>
</plist>
我把這一切都在一個bash腳本,並使用這裏是用shell變量替換文本的文檔。例如,$ packageVersion是我的應用程序的版本,例如「2.0.0.0」。字符串YOURAPPNAMEHERE也可以用一個shell變量替換。
cat <<EOF >"Distribution.xml"
<?xml version="1.0" encoding="utf-8"?>
...other text...
EOF
通過檢查iTunes安裝程序,您可以學到很多東西。下載安裝程序,安裝它,拖動pkg文件並展開:
$ /usr/sbin/pkgutil --expand Install\ iTunes.pkg iTunesExpanded
然後你就可以看到代碼和閒逛
感謝這個!這是一個很好的領先。特別指出以iTunes.pkg爲例。從來沒有想過檢查這個軟件包。 – radj