iOS的和Android的系统状态判断 App相册权限判断 将图片保存到手机相册

 uniapp 插件市场https://ext.dcloud.net.cn/plugin?id=594

import permision from "@/js_sdk/wa-permission/permission.js"

 判断是否给予权限,有权限返回true,否则返回fals

// 向用户发起授权请求
getImgUrl(image) {
  return this.$baseUrl + image
},
// 向用户发起授权请求
saveImg() {
  console.log(uni.getSystemInfoSync().platform);
  // 判断当前设备环境
  if (uni.getSystemInfoSync().platform === 'ios') {
    let photol = permision.judgeIosPermission("photoLibrary")
    if (photol == false) {
      uni.showModal({
        title: '提示',
        content: '您已经关闭相册权限,去设置',
        success: function(res) {
          if (res.confirm) {
            plus.runtime.openURL("app-settings:");
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        }
      });
    } else {
      this.storeQrcodeHandle()
    }
  } else if (uni.getSystemInfoSync().platform === 'android') {
    let photol = permision.requestAndroidPermission("photoLibrary")
    if (photol == false) {
      uni.showModal({
        title: '提示',
        content: '您已经关闭相册权限,去设置',
        success: function(res) {
          if (res.confirm) {
            plus.runtime.openURL("app-settings:");
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        }
      });
    } else {
      this.storeQrcodeHandle()
    }
  }
  console.log(photol);
},
// 保存二维码名片
storeQrcodeHandle() {
  uni.downloadFile({
    url: this.$baseUrl + this.qrcodeInfo.qrcode,
    success: (res) => {
      if (res.statusCode === 200) {
        //保存图片至相册
        uni.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function() {
            uni.showToast({
              title: "二维码名片保存成功",
              icon: "none"
            });
          },
          fail: function() {
            uni.showToast({
              title: "保存失败,请稍后重试",
              icon: "none"
            });
          }
        });
      }
    },
  })
},

IOS 

permission.judgeIosPermission('');

permissionID参数

参数名 说明 
location 位置
push 推送(限IOS,注意Android上推送并不是一个权限)
camera 摄像头
photoLibrary 相册
record 麦克风
contact 通讯录
calendar 日历
memo 备忘录

 Android

permision.requestAndroidPermission("")

你可能感兴趣的:(uniapp,javascript,前端,html)