12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- const checkIsIos = async () => {
- return new Promise((resolve => {
- uni.getSystemInfo({
- success: function(res) {
- resolve(res.platform === "ios")
- }
- });
- }))
- }
- /**
- * 授权前告知用户使用意图
- * @param content
- * @returns
- */
- showAuthTipModal = async (authorize) => {
- // #ifdef H5
- if (1 === 1) {
- return true
- }
- // #endif
- // ios端在manifest.json配置权限使用说明,以下权限判断仅在安卓端可用
- let isIos = await checkIsIos()
- if (isIos) return true
- let compat = plus.android.importClass('androidx.core.content.ContextCompat')
- let context = plus.android.runtimeMainActivity()
- let result = compat.checkSelfPermission(context, authorize)
- console.log("result===", result);
- if (result === 0) return true
- // // 如果已经授权直接返回
- const contentData = {
- ['android.permission.ACCESS_FINE_LOCATION']: {
- title: "定位权限说明",
- describe: "用于获取天气信息"
- },
- ["android.permission.READ_EXTERNAL_STORAGE"]: {
- title: "相册权限说明",
- describe: "用于获取图片文件信息、识别/上传文件内容"
- },
- ["android.permission.CAMERA"]: {
- title: "拍摄权限说明",
- describe: "用于拍照上传用户头像、识别物品信息或上传图片资料信息"
- },
- }
- return new Promise((resolve) => {
- uni.showModal({
- title: contentData[authorize].title,
- content: contentData[authorize].describe,
- success: (res) => {
- resolve(!!res.confirm)
- },
- fail: () => {
- }
- })
- })
- },
- /**
- * 用户拒绝授权提示手动授权
- */
- showManualAuth = async (authorize) => {
- let isIos = await checkIsIos()
- if (isIos) return true
- const contentData = {
- ['android.permission.ACCESS_FINE_LOCATION']: "获取定位权限失败,请手动打开授权或检查系统定位开关",
- ["android.permission.READ_EXTERNAL_STORAGE"]: "获取相册权限失败,请手动打开授权",
- ["android.permission.CAMERA"]: "获取拍摄权限失败,请手动打开授权",
- ["android.permission.CALL_PHONE"]: "获取拨打电话权限失败,请手动打开授权",
- }
- uni.showModal({
- title: '提示',
- content: contentData[authorize],
- confirmText: "去设置",
- success: (res) => {
- if (res.confirm) {
- uni.openAppAuthorizeSetting({
- success(res) {
- console.log(res);
- }
- });
- }
- if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- }
-
- module.exports = {
- showAuthTipModal: showAuthTipModal,
- showManualAuth: showManualAuth,
- }
|