From 07f38b82ab9113b47f7c983ead0115a653092692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E7=A8=8B=E8=AE=AD?= Date: Wed, 1 Nov 2023 22:23:41 +0800 Subject: [PATCH] Version_0.2.5-fix1 --- dist/index.js | 66 +++++++++++++++++++++++++++++++++++++++++-- esm/permission.js | 64 ++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- src/permission.ts | 54 +++++++++++++++++++++++++++++++++-- types/permission.d.ts | 1 + 5 files changed, 181 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index aca4112..09b31ec 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,5 @@ /*! - * @uni-helper/galanga 0.2.5 (https://github.com/uni-helper/galanga) + * @uni-helper/galanga 0.2.5-fix1 (https://github.com/uni-helper/galanga) * API https://galanga.censujiang.com/api/ * Copyright 2014-2023 censujiang. All Rights Reserved * Licensed under Apache License 2.0 (https://github.com/uni-helper/galanga/blob/master/LICENSE) @@ -940,6 +940,57 @@ const notificationPermission = { // #endif return result; }, + request: async () => { + let result; + // #ifdef H5 + result = await notificationPermission$1.request(); + // #endif + // #ifdef APP-PLUS + if (isIOS === true) { + const UIApplication = plus.ios.import("UIApplication"); + const app = UIApplication.sharedApplication(); + let enabledTypes = 0; + if (app.currentUserNotificationSettings) { + const settings = app.currentUserNotificationSettings(); + enabledTypes = settings.plusGetAttribute("types"); + console.log("enabledTypes1:" + enabledTypes); + if (enabledTypes == 0) { + result = false; + } + else { + result = true; + } + plus.ios.deleteObject(settings); + } + else { + enabledTypes = app.enabledRemoteNotificationTypes(); + if (enabledTypes == 0) { + result = false; + } + else { + result = true; + } + } + plus.ios.deleteObject(app); + plus.ios.deleteObject(UIApplication); + } + else { + result = await requestAndroidPermission('android.permission.ACCESS_NOTIFICATION_POLICY'); + } + // #endif + // #ifndef H5 || APP-PLUS + //小程序暂时没有思路去请求,暂时只做检查 + result = await notificationPermission.check().then((check) => { + if (checkNull(check)) { + return false; + } + return check; + }).catch(() => { + return false; + }); + // #endif + return result; + } }; // 剪切板权限相关 const clipboardPermission = { @@ -982,7 +1033,18 @@ const locationPermission = { // #ifdef H5 result = await locationPermission$1.check(); // #endif - // #ifndef H5 + // #ifdef APP-PLUS + if (isIOS === true) { + const locationManger = plus.ios.import("CLLocationManager"); + const status = locationManger.authorizationStatus(); + result = (status != 2); + plus.ios.deleteObject(locationManger); + } + else { + result = await requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION'); + } + // #endif + // #ifndef H5 || APP-PLUS result = await uni.getLocation().then(() => { return true; }).catch(() => { diff --git a/esm/permission.js b/esm/permission.js index 2ef813e..7883be0 100644 --- a/esm/permission.js +++ b/esm/permission.js @@ -56,6 +56,57 @@ export const notificationPermission = { // #endif return result; }, + request: async () => { + let result; + // #ifdef H5 + result = await origin.notificationPermission.request(); + // #endif + // #ifdef APP-PLUS + if (isIOS === true) { + const UIApplication = plus.ios.import("UIApplication"); + const app = UIApplication.sharedApplication(); + let enabledTypes = 0; + if (app.currentUserNotificationSettings) { + const settings = app.currentUserNotificationSettings(); + enabledTypes = settings.plusGetAttribute("types"); + console.log("enabledTypes1:" + enabledTypes); + if (enabledTypes == 0) { + result = false; + } + else { + result = true; + } + plus.ios.deleteObject(settings); + } + else { + enabledTypes = app.enabledRemoteNotificationTypes(); + if (enabledTypes == 0) { + result = false; + } + else { + result = true; + } + } + plus.ios.deleteObject(app); + plus.ios.deleteObject(UIApplication); + } + else { + result = await requestAndroidPermission('android.permission.ACCESS_NOTIFICATION_POLICY'); + } + // #endif + // #ifndef H5 || APP-PLUS + //小程序暂时没有思路去请求,暂时只做检查 + result = await notificationPermission.check().then((check) => { + if (origin.checkNull(check)) { + return false; + } + return check; + }).catch(() => { + return false; + }); + // #endif + return result; + } }; // 剪切板权限相关 export const clipboardPermission = { @@ -98,7 +149,18 @@ export const locationPermission = { // #ifdef H5 result = await origin.locationPermission.check(); // #endif - // #ifndef H5 + // #ifdef APP-PLUS + if (isIOS === true) { + const locationManger = plus.ios.import("CLLocationManager"); + const status = locationManger.authorizationStatus(); + result = (status != 2); + plus.ios.deleteObject(locationManger); + } + else { + result = await requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION'); + } + // #endif + // #ifndef H5 || APP-PLUS result = await uni.getLocation().then(() => { return true; }).catch(() => { diff --git a/package.json b/package.json index ec41570..2bee25b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uni-helper/galanga", - "version": "0.2.5", + "version": "0.2.5-fix1", "description": "JS common function library(UNI-APP version of Galanga)", "main": "esm/index.js", "jsnext:main": "esm/index.js", diff --git a/src/permission.ts b/src/permission.ts index 4952cea..4505afd 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -55,11 +55,51 @@ export const notificationPermission = { // #endif return result }, - request: async() =>{ + request: async () => { let result: boolean // #ifdef H5 result = await origin.notificationPermission.request() // #endif + // #ifdef APP-PLUS + if (isIOS === true) { + const UIApplication = plus.ios.import("UIApplication"); + const app = UIApplication.sharedApplication(); + let enabledTypes = 0; + if (app.currentUserNotificationSettings) { + const settings = app.currentUserNotificationSettings(); + enabledTypes = settings.plusGetAttribute("types"); + console.log("enabledTypes1:" + enabledTypes); + if (enabledTypes == 0) { + result = false; + } else { + result = true; + } + plus.ios.deleteObject(settings); + } else { + enabledTypes = app.enabledRemoteNotificationTypes(); + if (enabledTypes == 0) { + result = false; + } else { + result = true; + } + } + plus.ios.deleteObject(app); + plus.ios.deleteObject(UIApplication); + } else { + result = await requestAndroidPermission('android.permission.ACCESS_NOTIFICATION_POLICY') as boolean + } + // #endif + // #ifndef H5 || APP-PLUS + //小程序暂时没有思路去请求,暂时只做检查 + result = await notificationPermission.check().then((check) => { + if (origin.checkNull(check)) { + return false + } + return check + }).catch(() => { + return false + }) + // #endif return result } } @@ -106,7 +146,17 @@ export const locationPermission = { // #ifdef H5 result = await origin.locationPermission.check() // #endif - // #ifndef H5 + // #ifdef APP-PLUS + if (isIOS === true) { + const locationManger = plus.ios.import("CLLocationManager"); + const status = locationManger.authorizationStatus(); + result = (status != 2) + plus.ios.deleteObject(locationManger); + } else { + result = await requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION') as boolean + } + // #endif + // #ifndef H5 || APP-PLUS result = await uni.getLocation().then(() => { return true }).catch(() => { diff --git a/types/permission.d.ts b/types/permission.d.ts index 84bce11..9dd15b1 100644 --- a/types/permission.d.ts +++ b/types/permission.d.ts @@ -1,5 +1,6 @@ export declare const notificationPermission: { check: () => Promise; + request: () => Promise; }; export declare const clipboardPermission: { check: () => Promise;