downApp.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. export function checkUpdateApp() {
  2. plus.runtime.getProperty(plus.runtime.appid, function(widgetinfo) {
  3. if (widgetinfo.name == '冷链物流') {
  4. uni.request({
  5. url: 'https://www.pgyer.com/apiv2/app/check',
  6. data: {
  7. _api_key: '202eadee73f2051186b26106cc8bfed1',
  8. appKey: '970036fad7e2118d83dcdc5ac36eabc5'
  9. },
  10. success: check => {
  11. if (check.statusCode == 200 && check.data.code == 0 && check.data.data) {
  12. let data = check.data.data;
  13. let version = widgetinfo.version,
  14. appVersion = data.buildVersion,
  15. appName = widgetinfo.name,
  16. appurl = data.downloadURL,
  17. intro = '发现新的《冷链物流》APP,需要更新APP';
  18. if (data && version < appVersion) {
  19. uni.showModal({
  20. title: '更新提示',
  21. confirmText: '立即升级',
  22. content: intro,
  23. success: res => {
  24. if (res.confirm) {
  25. uni.showLoading({
  26. title: '正在更新',
  27. mask: true
  28. });
  29. uni.downloadFile({
  30. url: appurl,
  31. success: download => {
  32. if (download.statusCode ==
  33. 200) {
  34. plus.runtime.install(
  35. download
  36. .tempFilePath, {
  37. force: false
  38. },
  39. () => {
  40. uni
  41. .hideLoading();
  42. plus.runtime
  43. .restart(); //更新成功启动
  44. },
  45. err => {
  46. uni
  47. .hideLoading();
  48. uni.showToast({
  49. title: '更新失败,将跳转下载页面',
  50. icon: 'none',
  51. duration: 2000
  52. });
  53. }
  54. );
  55. setTimeout(function() {
  56. plus.runtime
  57. .openURL(
  58. appurl
  59. );
  60. }, 2000);
  61. }
  62. }
  63. });
  64. } else if (res.cancel) {
  65. console.log('用户点击取消');
  66. uni.showToast({
  67. title: '低版本无法继续使用,请先升级',
  68. icon: 'none',
  69. duration: 2000
  70. });
  71. //退出app
  72. setTimeout(function() {
  73. plus.runtime.quit();
  74. }, 2000);
  75. }
  76. },
  77. fail: () => {
  78. uni.hideLoading();
  79. }
  80. });
  81. } else {
  82. console.log('暂无新版本=====')
  83. }
  84. }
  85. }
  86. });
  87. } else {
  88. //非安卓
  89. }
  90. });
  91. }