【快应用】小程序转快应用中如何获取用户已授权的权限

发布时间 2023-11-23 11:36:39作者: Mayism123
 【关键词】

权限、SystemInfo、setting

 

【问题背景】

小程序转快应用,用户在使用快应用的过程中如果产生了一些授权行为,开发者是否有办法去收集到用户已经授权过的权限呢,从而进行更好管理呢?

 

【解决方案】

小程序转快应用中是可行的,方法有如下两种:

1、  通过qa.getSystemInfoSync()接口返回的信息。如下图所示:

代码:

  getset2() {

    const sysInfo = qa.getSystemInfoSync()

    console.log(sysInfo)

  }

运行结果:

 "devicePixelRatio":3,"albumAuthorized":false,"cameraAuthorized":false,"locationAuthorized":false,"microphoneAuthorized":false,"notificationAuthorized":false,"notificationAlertAuthorized":false,"notificationBadgeAuthorized":false,"notificationSoundAuthorized":false,"bluetoothEnabled":false,"locationEnabled":true,"wifiEnabled":true,

2、  通过qa.getSetting获取当前用户的设置。

代码:

     qa.getSetting({

      success(res) {

        console.log("getSetting success, authSetting = " + JSON.stringify(res.authSetting))

      }

    })

运行结果:

 getSetting success, authSetting = {"scope.userLocation":false,"scope.writePhotosAlbum":true,"scope.record":false,"scope.camera":false,"scope.userInfo":false,"scope.address":false,"scope.invoiceTitle":false,"scope.invoice":false,"scope.werun":false}