uniapp开发app更新版本

onLaunch: function () {
        let that = this;
        uni.getSystemInfo({
            success(res) {
                that.platform = res.platform; // 获取系统平台 ios 安卓
            },
        });
        // 获取应用属性
        plus.runtime.getProperty(plus.runtime.appid, function (inf) {
            that.version = plus.runtime.versionCode;
            console.log(that.version);
        });
        uni.request({
            method: "GET",
            url: "服务端响应的最新apk版本信息",
            header: {
                "Content-Type": "application/x-www-form-urlencoded",
            },
        })
            .then((res) => {
                let data = res.data;
                if (!data.code) {
                    if (that.version != data.data.versionCode && that.version < data.data.versionCode) {
                        let contentText = `APP已发布新版本${data.data.versionName},为了您的正常使用体验,请更新版本后使用`;
                        let downloadText = "下载成功,现在安装吗";
                        let downloadtip = "正在下载";
                        uni.showModal({
                            title: "更新提示",
                            content: contentText,
                            cancelText: "取消",
                            confirmText: "去更新",
                            success: function (res) {
                                if (res.confirm) {
                                    if (that.platform == "android") {
                                        var prg = 0;
                                        var showLoading = plus.nativeUI.showWaiting(downloadtip); //创建一个showWaiting对象
                                        // 执行下载
                                        var downloadTask = uni.downloadFile({
                                            url: data.data.download, // 下载地址
                                            success: (downloadResult) => {
                                                plus.nativeUI.closeWaiting();
                                                if (downloadResult.statusCode == 200) {
                                                    uni.showModal({
                                                        title: "",
                                                        content: downloadText,
                                                        confirmText: "安装",
                                                        cancelText: "取消",
                                                        confirmColor: "#EE8F57",
                                                        success: (res) => {
                                                            if (res.confirm) {
                                                                plus.runtime.install(downloadResult.tempFilePath, {
                                                                    force: true,
                                                                });
                                                            }
                                                        },
                                                    });
                                                }
                                            },
                                        });
                                        downloadTask.onProgressUpdate((res) => {
                                            that.progressNum = res.progress;
                                            prg = parseInt(res.progress);
                                            showLoading.setTitle(downloadtip + prg + "%  ");
                                        });
                                    } else if (that.platform == "ios") {
                                        var appurl = "ios应用商店的应用地址";
                                        plus.runtime.openURL(appurl, function (res) {
                                            console.log(res);
                                        });
                                    }
                                } else if (res.cancel) {
                                }
                            },
                        });
                    }
                }
            })
            .catch((err) => {
                console.log(err);
            });
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值