Skip to content

Commit

Permalink
Version_0.2.5-fix1
Browse files Browse the repository at this point in the history
  • Loading branch information
censujiang committed Nov 1, 2023
1 parent cc9949c commit 07f38b8
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 6 deletions.
66 changes: 64 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(() => {
Expand Down
64 changes: 63 additions & 1 deletion esm/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
54 changes: 52 additions & 2 deletions src/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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(() => {
Expand Down
1 change: 1 addition & 0 deletions types/permission.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export declare const notificationPermission: {
check: () => Promise<boolean>;
request: () => Promise<boolean>;
};
export declare const clipboardPermission: {
check: () => Promise<boolean>;
Expand Down

0 comments on commit 07f38b8

Please sign in to comment.