小程序在真机调试的时候能保存网络图片,发布的体验版保存不了,这是为什么

//获取授权
saveImg(){

       let that = this;
       uni.getSetting({
           success: function(res){
               //不存在相册授权
               if (!res.authSetting['scope.writePhotosAlbum']){
                   uni.authorize({
                       scope: 'scope.writePhotosAlbum',
                       success: function(){
                           that.savePhoto();
                           that.isPic = false;
                       },
                       fail: function(err){
                           that.isPic = true;
                       }
                   })
               }else{
                   that.savePhoto(); 
               }
           }
       })
    },

//授权被拒绝后重新获取

    handleSetting(e){
        this.share = true;
        var that = this;
        uni.openSetting({
          success(res) {
            that.savePhoto(); 

// uni.showToast({
// title: '保存成功'
// })

            that.isPic = false;
          },
          fail(res) {
            uni.showModal({
                title: '警告',
                content: '不授权无法保存',
                showCancel: false
            })
            that.isPic = true;
          }
        });
    },

//下载图片

    savePhoto(){
        console.log('执行保存函数')
        let urlStr = this.imgSrc;
        var that = this;
        console.log(urlStr);
        uni.getImageInfo({
            src: ''+that.imgSrc+'',
            success: function (res) {
                console.log('图片信息');
                console.log(res);
                uni.saveImageToPhotosAlbum({
                    filePath: res.path,
                    success: function (data) {
                        uni.showToast({
                            title: '保存成功',
                            icon: 'success',
                            duration: 1500
                        })
                    }
                })
            },
            fail() {
                console.log(that.imgSrc)
                console.log('下载失败')
            }
        })
    },
阅读 3.6k
1 个回答

一般情况应该是,没设置合法域名
可以真机调试试试看

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题