initConfig.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function checkNew(){
  2. const updateManager = uni.getUpdateManager()
  3. updateManager.onCheckForUpdate(function (res) {
  4. // 请求完新版本信息的回调
  5. })
  6. updateManager.onUpdateReady(function () {
  7. uni.showModal({
  8. title: '更新提示',
  9. content: '新版本已经准备好,立即重启应用?',
  10. showCancel: false,
  11. success: function (res) {
  12. if (res.confirm) {
  13. updateManager.applyUpdate();
  14. }
  15. }
  16. })
  17. })
  18. updateManager.onUpdateFailed(function () {
  19. uni.showModal({title: '温馨提示',content: '新版本下载失败,请卸载小程序再重试',showCancel: false});
  20. })
  21. }
  22. export default function init(){
  23. uni.getNetworkType({
  24. success: res => {
  25. const { networkType } = res;
  26. if (!['none'].includes(networkType)) {
  27. // 检查小程序更新
  28. checkNew()
  29. }else{
  30. uni.showToast({
  31. title: '当前无网络访问,请开启网络',
  32. icon: 'none'
  33. })
  34. }
  35. },
  36. fail: () => {
  37. uni.showToast({
  38. title: '获取网络失败,网络不稳定',
  39. icon: 'none'
  40. })
  41. }
  42. })
  43. }