uniapp app更新

uniapp app更新
这个版本要随之增加,不然刚更新时直接用app, 新包增加的那些页面跳转会有问题,不能跳新的页面

javascript 复制代码
//app更新检测
updataApp(){
	const that = this;
	uni.showLoading({title:'加载中...'})
	plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
		let currentVersion = widgetInfo.versionCode; //获取当前版本号
		console.log('当前版本',currentVersion)
		that.$api.getLatestVersion()
		.then(res =>{
			console.log('版本',res) 
			if(res.code == 200){
				let newVersion = res.data.version;
				if (currentVersion < newVersion) {
					that.downloadUrl = that.baseUrl + res.data.path;
					console.log('下载路径',that.downloadUrl)
					that.openPop(666)
				}
			}
		})
	})
},
//APP更新
actionApp(){
	const that = this;
	const downloadTask = uni.downloadFile({
		url: that.downloadUrl,
		success: (downloadResult) => {
			console.log('?????',downloadResult)
			plus.runtime.install(
				downloadResult.tempFilePath, {
					force: true
				},
				function() {
					that.closePop()
					uni.showToast({
						title: '安装成功,请重新启动',
						icon: 'none',
						mask:true
					})
					// that.clearCache()
					plus.runtime.restart();
				},
				function(e) {
					console.log(e)
					that.closePop()
					uni.showToast({
						title: '安装失败',
						icon: 'none',
						mask:true
					})
					//关闭应用
					setTimeout(() =>{
						plus.runtime.quit();
					},1000)
				})
		},
		fail: (err) => {
			that.closePop()
			console.log(err);
			uni.showToast({
				title: '下载失败',
				icon: 'none',
				mask:true
			})
			//关闭应用
			setTimeout(() =>{
				plus.runtime.quit();
			},1000)
		}
	})
	
	//下载进度监听
	downloadTask.onProgressUpdate((res) => {
		if (res.progress <= 99) {
			console.log('下载进度'+res.progress+'%');
			that.schedule = res.progress;
		}
	});
},
//清除app更新后的文件缓存
clearCache(type = 2) {
	// 第一种方式:彻底清理存储数据(用户数据),包括用户权限和缓存,但是这种方式清理之后当前的app会闪退出去,只有等待用户重新拉起。
	if (type == 1) {
		plus.android.importClass("android.app.ActivityManager");
		var Context = plus.android.importClass("android.content.Context");
		var am = plus.android.runtimeMainActivity().getSystemService(Context.ACTIVITY_SERVICE);
		am.clearApplicationUserData();
		return
	}
	// 第二种方式:清理内存存储文件(部分用户数据),不会清理用户权限,也不会闪退,一些静态的图片会被清理掉。
	let main = plus.android.runtimeMainActivity();
	let sdRoot1 = main.getFilesDir();
	let filesOne = plus.android.invoke(sdRoot1, "listFiles");
	let lenOne = filesOne.length;
	for (let i = 0; i < lenOne; i++) {
		let filePath = '' + filesOne[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径
		plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
			if (entry.isDirectory) {
				entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录
					console.log('清理文件数据完成')
				}, function(e) {
					console.log(e.message)
				});
			} else {
				entry.remove(function(entry) { //递归删除其下的所有文件及子目录
					console.log('清理文件数据完成')
				}, function(e) {
					console.log(e.message)
				});
			}
		}, function(e) {
			console.log('清理文件数据失败')
		});
	};
},
相关推荐
2501_916007472 分钟前
手机使用过的痕迹能查到吗?完整查询指南与步骤
android·ios·智能手机·小程序·uni-app·iphone·webview
Amewin6 小时前
在vue3+uniapp+vite中挂载全局属性方法
javascript·vue.js·uni-app
2501_9151063215 小时前
App HTTPS 抓包 工程化排查与工具组合实战
网络协议·ios·小程序·https·uni-app·php·iphone
dcloud_jibinbin16 小时前
【uniapp】小程序体积优化,分包异步化
前端·vue.js·webpack·性能优化·微信小程序·uni-app
2501_9160088917 小时前
金融类 App 加密加固方法,多工具组合的工程化实践(金融级别/IPA 加固/无源码落地/Ipa Guard + 流水线)
android·ios·金融·小程序·uni-app·iphone·webview
2501_9159214317 小时前
Fastlane 结合 开心上架(Appuploader)命令行版本实现跨平台上传发布 iOS App 免 Mac 自动化上架实战全解析
android·macos·ios·小程序·uni-app·自动化·iphone
游戏开发爱好者819 小时前
iOS 上架要求全解析,App Store 审核标准、开发者准备事项与开心上架(Appuploader)跨平台免 Mac 实战指南
android·macos·ios·小程序·uni-app·iphone·webview
00后程序员张20 小时前
混淆 iOS 类名与变量名的实战指南,多工具组合把混淆做成工程能力(混淆 iOS 类名变量名/IPA 成品混淆Ipa/Guard CLI 实操)
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
iOS文件管理工具深度剖析,从系统沙盒到跨平台文件操作的多工具协同实践
android·macos·ios·小程序·uni-app·cocoa·iphone
shykevin1 天前
uni-app x开发商城系统,扩展组件uni-ui实现底部商品导航
uni-app