| 123456789101112131415161718192021222324252627282930313233343536 |
- /** 检查是否存在新版本 */
- export const useGetUpdateManager = () => {
- return new Promise((resolve, reject) => {
- uni.getUpdateManager().onCheckForUpdate(function (res) {
- // 请求完新版本信息的回调
- if (res.hasUpdate) {
- //如果有新版本
- // 小程序有新版本,会主动触发下载操作(无需开发者触发)
- uni.getUpdateManager().onUpdateReady(function () {
- //当新版本下载完成,会进行回调
- uni.showModal({
- title: '更新提示',
- content: '新版本已经准备好,单击确定重启应用',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- uni.getUpdateManager().applyUpdate();
- }
- },
- });
- });
- // 小程序有新版本,会主动触发下载操作(无需开发者触发)
- uni.getUpdateManager().onUpdateFailed(function () {
- //当新版本下载失败,会进行回调
- uni.showModal({
- title: '提示',
- content: '检查到有新版本,但下载失败,请检查网络设置',
- showCancel: false,
- });
- });
- }
- resolve(res.hasUpdate);
- });
- });
- };
|