| | |
| | | success: (modalResult) => { |
| | | if (modalResult.confirm) { |
| | | confirmed = true |
| | | openDownloadUrl(updateInfo.downloadUrl) |
| | | startAppUpdate(updateInfo.downloadUrl) |
| | | return |
| | | } |
| | | }, |
| | |
| | | } |
| | | |
| | | /** |
| | | * 打开后台配置的安装包或下载地址。 |
| | | * iOS 跳转 App Store;Android 下载完整 APK 后拉起系统安装界面。 |
| | | */ |
| | | function openDownloadUrl(downloadUrl) { |
| | | function startAppUpdate(downloadUrl) { |
| | | if (!downloadUrl) { |
| | | return |
| | | } |
| | | plus.runtime.openURL(downloadUrl) |
| | | if (isIosPlatform()) { |
| | | plus.runtime.openURL(downloadUrl) |
| | | return |
| | | } |
| | | const downloadTask = plus.downloader.createDownload(downloadUrl, {}, (download, status) => { |
| | | if (status !== 200 || !download.filename) { |
| | | handleUpdateFailure('安装包下载失败,请重试') |
| | | return |
| | | } |
| | | const apkPath = plus.io.convertLocalFileSystemURL(download.filename) |
| | | plus.runtime.install(apkPath, {}, undefined, () => { |
| | | handleUpdateFailure('安装失败,请重试') |
| | | }) |
| | | }) |
| | | downloadTask.start() |
| | | } |
| | | |
| | | /** |
| | | * 静默查询当前 APP 是否存在可用更新,供页面展示更新状态。 |
| | | */ |
| | | export function queryAppVersionUpdate() { |
| | | // #ifndef APP-PLUS |
| | | return Promise.resolve(null) |
| | | // #endif |
| | | return resolveRuntimeVersionInfo() |
| | | .then((runtimeInfo) => requestVersionCheck(runtimeInfo)) |
| | | .then((payload) => { |
| | | const updateInfo = payload && payload.code === 0 ? payload.data : null |
| | | if (!updateInfo || updateInfo.hasUpdate !== true) { |
| | | return null |
| | | } |
| | | const downloadUrl = resolveUpdateUrl(updateInfo) |
| | | return downloadUrl ? Object.assign({}, updateInfo, { downloadUrl }) : null |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * 使用统一更新弹窗展示指定版本信息。 |
| | | */ |
| | | export function promptAppVersionUpdate(updateInfo) { |
| | | if (updateInfo && updateInfo.hasUpdate === true) { |
| | | showUpdateModal(updateInfo) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载或安装失败后重新开放更新入口。 |
| | | */ |
| | | function handleUpdateFailure(title) { |
| | | uni.showToast({ |
| | | title, |
| | | icon: 'none' |
| | | }) |
| | | if (latestUpdateInfo) { |
| | | setTimeout(() => { |
| | | showUpdateModal(latestUpdateInfo) |
| | | }, 1500) |
| | | } |
| | | } |
| | | |
| | | /** |