美文网首页
ionic3——更新app

ionic3——更新app

作者: 一只飞 | 来源:发表于2018-09-28 15:14 被阅读0次

    参考:https://www.cnblogs.com/BetterMyself/p/7116235.html
    过程中遇到了几个问题:
    1、更新下载进度时,要控制更新速度,也就是进度就算后发生变化,才改变显示;

    //下载的进度
        let newProgress = 0;
        fileTransfer.onProgress((progress)=>{
          /*{"bubbles":false,"cancelBubble":false,"cancelable":false,"lengthComputable":true,"loaded":1278957,"total":43921184,"target":null}*/
          let downloadProgress = Math.floor((progress.loaded / progress.total) * 100);
          //发现进度发生改变,更新显示
          if(newProgress != downloadProgress){
            newProgress = downloadProgress;
    
            //同步修改loading显示的进度值
            this.zone.run(() => {
              loadProgress.setContent("下载:"+newProgress+"%");
            });
    
            console.log("newProgress:"+newProgress);
            //大于99结束显示
            if (downloadProgress > 99) {
              loadProgress.dismiss();
            }
          }
    
        });
    

    2、ionic3中LoadingController多次create会弹出多个,需要创建一个,动态修改显示内容

    let loadProgress = this.loadingCtrl.create({
          spinner: 'ios',
          content: "下载:0%",
          cssClass: "loadingProgress"
        });
        loadProgress.present();
    
    //触发修改
    //import { NgZone } from '@angular/core';
    //constructor(private zone: NgZone) {}
    this.zone.run(() => {
           loadProgress.setContent("下载:"+newProgress+"%");
     });
    

    3、修改LoadingController样式,已经spinner颜色等


    image.png
    .loading-md .loading-wrapper {
      max-width: 90%;
      max-height: 90%;
      color: white;
      font-size: 1.2rem;
      background: var(--main);//替换
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .loadingProgress{
      .spinner-ios line {
        stroke: #9e9e9e;
      }
    }
    

    相关文章

      网友评论

          本文标题:ionic3——更新app

          本文链接:https://www.haomeiwen.com/subject/nirpoftx.html