macOS下Sparkle静默/后台自动更新配置问题求助
问题
我希望Sparkle在无需用户干预的情况下自动下载并安装更新,已在Info.plist中配置以下参数:
<key>SUEnableAutomaticChecks</key> <true/> <key>SUScheduledCheckInterval</key> <integer>3600</integer> <key>SUAutomaticallyUpdate</key> <true/> <key>SUAllowsAutomaticUpdates</key> <true/>
但当更新周期(1小时)结束后,仍会弹出新版本可用的提示窗口。
查阅Sparkle文档得知:
In Sparkle 2, updates will be downloaded but not installed automatically if authorization is required. In all versions of Sparkle, if the application hasn’t quit for 1 week the user will be presented with installing the downloaded update (unless the updater delegate overrides this).
我的应用位于Applications文件夹,删除时Finder无需额外权限,不存在授权问题,且更新包为应用zip而非pkg,请问是否还需额外配置或代码实现需求?
解决方案
- 非沙箱应用需实现代理逻辑:Sparkle 2中
SUAutomaticallyUpdate默认只对沙箱应用生效,非沙箱应用即使配置了该键,仍会弹出提示。你需要实现SPUUpdaterDelegate的两个关键方法,跳过所有用户交互:// 跳过下载权限提示 - (BOOL)updaterShouldPromptForPermissionToDownloadUpdates:(SPUUpdater *)updater { return NO; } // 自动确认安装更新 - (BOOL)updater:(SPUUpdater *)updater shouldInstallUpdate:(SUAppcastItem *)update { return YES; } - 检查更新包签名一致性:更新包的签名必须和当前应用完全匹配,否则Sparkle会触发安全提示,无法静默完成安装。
- 处理长运行周期提示:如果应用连续运行超过1周,Sparkle会强制弹出安装提示。若要避免这种情况,需在代理中重写
updaterShouldShowInstallUpdateAlert:方法并返回NO:- (BOOL)updaterShouldShowInstallUpdateAlert:(SPUUpdater *)updater { return NO; } - 确认无其他逻辑干扰:确保没有自定义代码修改了Sparkle的自动更新设置,比如动态禁用
SUAllowsAutomaticUpdates。
内容的提问来源于stack exchange,提问作者njLT
相关产品推荐
相关产品推荐

