Skip to content

Commit

Permalink
权限获取
Browse files Browse the repository at this point in the history
  • Loading branch information
censujiang committed Nov 2, 2023
1 parent 07f38b8 commit 0ffa1f1
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/permission.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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(() => {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 0ffa1f1

Please sign in to comment.