From 0ffa1f1d6ded16a33a8b337748920dbaea319a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E7=A8=8B=E8=AE=AD?= Date: Thu, 2 Nov 2023 21:54:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.ts | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/permission.ts b/src/permission.ts index 4505afd..68a86cb 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -1,4 +1,9 @@ -import * as origin from 'galanga' +import { + checkNull, + notificationPermission as notificationPermissionO, + clipboardPermission as clipboardPermissionO, + locationPermission as locationPermissionO +} from 'galanga'; declare const uni: any declare const plus: any @@ -11,7 +16,7 @@ export const notificationPermission = { check: async () => { let result: boolean | null // #ifdef H5 - result = await origin.notificationPermission.check() + result = await notificationPermissionO.check() // #endif // #ifdef MP || QUICKAPP-WEBVIEW result = await uni.getSetting().then((res) => { @@ -58,7 +63,7 @@ export const notificationPermission = { request: async () => { let result: boolean // #ifdef H5 - result = await origin.notificationPermission.request() + result = await notificationPermissionO.request() // #endif // #ifdef APP-PLUS if (isIOS === true) { @@ -86,13 +91,28 @@ export const notificationPermission = { plus.ios.deleteObject(app); plus.ios.deleteObject(UIApplication); } else { - result = await requestAndroidPermission('android.permission.ACCESS_NOTIFICATION_POLICY') as boolean + //首先判断安卓13引入的新权限 + result = await requestAndroidPermission('android.permission.POST_NOTIFICATIONS') as boolean + //不运行的时候不通知?没关系,我们再试试旧的权限,反正我们只需要知道应用到底能不能发起通知 + if (result == false) { + const main = plus.android.runtimeMainActivity(); + let NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat"); + if (checkNull(NotificationManagerCompat)) { + NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat"); + } + const notificationManagerResult = NotificationManagerCompat.from(main).areNotificationsEnabled() + if (!notificationManagerResult) { + result = false + } else { + result = true + } + } } // #endif // #ifndef H5 || APP-PLUS //小程序暂时没有思路去请求,暂时只做检查 result = await notificationPermission.check().then((check) => { - if (origin.checkNull(check)) { + if (checkNull(check)) { return false } return check @@ -109,7 +129,7 @@ export const clipboardPermission = { check: async () => { let result: boolean | null // #ifdef H5 - result = await origin.clipboardPermission.check() + result = await clipboardPermissionO.check() // #endif // #ifndef H5 result = await uni.getClipboardData().then(() => { @@ -123,11 +143,11 @@ export const clipboardPermission = { request: async () => { let result: boolean // #ifdef H5 - result = await origin.clipboardPermission.request() + result = await clipboardPermissionO.request() // #endif // #ifndef H5 result = await clipboardPermission.check().then((check) => { - if (origin.checkNull(check)) { + if (checkNull(check)) { return false } return check @@ -144,7 +164,7 @@ export const locationPermission = { check: async () => { let result: boolean | null // #ifdef H5 - result = await origin.locationPermission.check() + result = await locationPermissionO.check() // #endif // #ifdef APP-PLUS if (isIOS === true) { @@ -168,11 +188,11 @@ export const locationPermission = { request: async () => { let result: boolean // #ifdef H5 - result = await origin.locationPermission.request() + result = await locationPermissionO.request() // #endif // #ifdef MP || QUICKAPP-WEBVIEW result = await locationPermission.check().then((check) => { - if (origin.checkNull(check)) { + if (checkNull(check)) { return false } return check