iOS and Android system status judgment App photo album permission judgment Save pictures to phone photo album

 uniapp plug-in market https://ext.dcloud.net.cn/plugin?id=594

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

 Determine whether to grant permission, return true if there is permission, otherwise return false

// 向用户发起授权请求
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 parameter

parameter name illustrate 
location Location
push Push (only for IOS, note that push is not a permission on Android)
camera Camera
photoLibrary photo album
record microphone
contact address book
calendar calendar
memo memorandum

 Android

permision.requestAndroidPermission("")

Guess you like

Origin blog.csdn.net/weixin_44523517/article/details/129929527