Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
05f988a0
U
uni-api
项目概览
DCloud
/
uni-api
通知
690
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
05f988a0
编写于
10月 30, 2023
作者:
DCloud-yyl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
开源uni.getAppAuthorizeSetting
上级
4310d2de
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
408 addition
and
0 deletion
+408
-0
uni_modules/uni-getAppAuthorizeSetting/changelog.md
uni_modules/uni-getAppAuthorizeSetting/changelog.md
+0
-0
uni_modules/uni-getAppAuthorizeSetting/package.json
uni_modules/uni-getAppAuthorizeSetting/package.json
+93
-0
uni_modules/uni-getAppAuthorizeSetting/readme.md
uni_modules/uni-getAppAuthorizeSetting/readme.md
+6
-0
uni_modules/uni-getAppAuthorizeSetting/utssdk/app-android/index.uts
...s/uni-getAppAuthorizeSetting/utssdk/app-android/index.uts
+76
-0
uni_modules/uni-getAppAuthorizeSetting/utssdk/app-ios/index.uts
...dules/uni-getAppAuthorizeSetting/utssdk/app-ios/index.uts
+0
-0
uni_modules/uni-getAppAuthorizeSetting/utssdk/interface.uts
uni_modules/uni-getAppAuthorizeSetting/utssdk/interface.uts
+233
-0
未找到文件。
uni_modules/uni-getAppAuthorizeSetting/changelog.md
0 → 100644
浏览文件 @
05f988a0
uni_modules/uni-getAppAuthorizeSetting/package.json
0 → 100644
浏览文件 @
05f988a0
{
"id"
:
"uni-getAppAuthorizeSetting"
,
"displayName"
:
"uni-getAppAuthorizeSetting"
,
"version"
:
"1.0.0"
,
"description"
:
"uni-getAppAuthorizeSetting"
,
"keywords"
:
[
"uni-getAppAuthorizeSetting"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.6.8"
},
"dcloudext"
:
{
"type"
:
"uts"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"uni-ext-api"
:
{
"uni"
:
{
"getAppAuthorizeSetting"
:
{
"name"
:
"getAppAuthorizeSetting"
,
"app"
:
{
"js"
:
false
,
"kotlin"
:
true
,
"swift"
:
false
}
}
}
},
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"u"
,
"aliyun"
:
"u"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"u"
,
"vue3"
:
"u"
},
"App"
:
{
"app-android"
:
"u"
,
"app-ios"
:
"u"
},
"H5-mobile"
:
{
"Safari"
:
"u"
,
"Android Browser"
:
"u"
,
"微信浏览器(Android)"
:
"u"
,
"QQ浏览器(Android)"
:
"u"
},
"H5-pc"
:
{
"Chrome"
:
"u"
,
"IE"
:
"u"
,
"Edge"
:
"u"
,
"Firefox"
:
"u"
,
"Safari"
:
"u"
},
"小程序"
:
{
"微信"
:
"u"
,
"阿里"
:
"u"
,
"百度"
:
"u"
,
"字节跳动"
:
"u"
,
"QQ"
:
"u"
,
"钉钉"
:
"u"
,
"快手"
:
"u"
,
"飞书"
:
"u"
,
"京东"
:
"u"
},
"快应用"
:
{
"华为"
:
"u"
,
"联盟"
:
"u"
}
}
}
}
}
\ No newline at end of file
uni_modules/uni-getAppAuthorizeSetting/readme.md
0 → 100644
浏览文件 @
05f988a0
# uni-getAppAuthorizeSetting
### 开发文档
[
UTS 语法
](
https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html
)
[
UTS API插件
](
https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
)
[
UTS 组件插件
](
https://uniapp.dcloud.net.cn/plugin/uts-component.html
)
[
Hello UTS
](
https://gitcode.net/dcloud/hello-uts
)
\ No newline at end of file
uni_modules/uni-getAppAuthorizeSetting/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
05f988a0
import { GetAppAuthorizeSetting, GetAppAuthorizeSettingResult } from "../interface.uts";
import UTSAndroid from 'io.dcloud.uts.UTSAndroid';
import PackageManager from 'android.content.pm.PackageManager';
import Manifest from 'android.Manifest';
import NotificationManagerCompat from 'androidx.core.app.NotificationManagerCompat';
export const getAppAuthorizeSetting : GetAppAuthorizeSetting = function () : GetAppAuthorizeSettingResult {
const context = UTSAndroid.getUniActivity()!!;
const cameraPermission = [Manifest.permission.CAMERA];
const cameraGranted = UTSAndroid.checkSystemPermissionGranted(context, cameraPermission);
let cameraResult = cameraGranted ? "authorized" : "denied";
if (!cameraGranted && !hasDefinedInManifest(Manifest.permission.CAMERA)) {
cameraResult = "config error";
}
const locationPermission = [Manifest.permission.ACCESS_COARSE_LOCATION];
const coarseLocationGranted = UTSAndroid.checkSystemPermissionGranted(context, locationPermission);
let coarseLocationResult = coarseLocationGranted ? "authorized" : "denied";
if (!coarseLocationGranted && !hasDefinedInManifest(Manifest.permission.ACCESS_COARSE_LOCATION)) {
coarseLocationResult = "config error";
}
const fineLocationPermission = [Manifest.permission.ACCESS_FINE_LOCATION];
const fineLocationGranted = UTSAndroid.checkSystemPermissionGranted(context, fineLocationPermission);
let accuracy = coarseLocationGranted ? "reduced" : "unsupported";
if (coarseLocationGranted && fineLocationGranted) {
accuracy = "full";
}
const recordAudioPermission = [Manifest.permission.RECORD_AUDIO];
const recordAudioGranted = UTSAndroid.checkSystemPermissionGranted(context, recordAudioPermission);
let recordAudioResult = recordAudioGranted ? "authorized" : "denied";
if (!recordAudioGranted && !hasDefinedInManifest(Manifest.permission.RECORD_AUDIO)) {
recordAudioResult = "config error";
}
const compat = NotificationManagerCompat.from(context);
const notificationResult = compat.areNotificationsEnabled() ? "authorized": "denied"
let result : GetAppAuthorizeSettingResult = {
cameraAuthorized: cameraResult,
locationAuthorized: coarseLocationResult,
locationAccuracy: accuracy,
microphoneAuthorized: recordAudioResult,
notificationAuthorized: notificationResult,
albumAuthorized: null,
bluetoothAuthorized: null,
locationReducedAccuracy: null,
notificationAlertAuthorized: null,
notificationBadgeAuthorized: null,
notificationSoundAuthorized: null,
phoneCalendarAuthorized: null
}
return result
};
const hasDefinedInManifest = function (permission : string) : boolean {
try {
const context = UTSAndroid.getAppContext()!!;
const packageInfo = context.getPackageManager().getPackageInfo(context.getApplicationInfo().packageName, PackageManager.GET_PERMISSIONS);
if (packageInfo != null) {
for (const requestPermission in packageInfo.requestedPermissions) {
if (permission == requestPermission) {
return true;
}
}
}
} catch (e : Exception) {
return false
}
return false;
}
\ No newline at end of file
uni_modules/uni-getAppAuthorizeSetting/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
05f988a0
uni_modules/uni-getAppAuthorizeSetting/utssdk/interface.uts
0 → 100644
浏览文件 @
05f988a0
export interface Uni {
/**
* getAppAuthorizeSetting()
* @description
* 获取 APP 授权设置。
* @param {void}
* @return {GetAppAuthorizeSettingResult}
* @tutorial http://uniapp.dcloud.io/api/system/getappauthorizesetting
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4",
* "uniVer": "√",
* "unixVer": "3.9+"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
* @example
```typescript
uni.getAppAuthorizeSetting()
```
*/
getAppAuthorizeSetting(): GetAppAuthorizeSettingResult;
}
export type GetAppAuthorizeSetting = () => GetAppAuthorizeSettingResult;
export type GetAppAuthorizeSettingResult = {
/**
* 允许 App 使用相册的开关(仅 iOS 支持)
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* @type 'authorized' | 'denied' | 'not determined'
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
*/
albumAuthorized: string | null,
/**
* 允许 App 使用蓝牙的开关(仅 iOS 支持)
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: Android平台没有该值;iOS平台:表示没有在 `manifest.json -> App模块配置` 中配置 `BlueTooth(低功耗蓝牙)` 模块
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
*/
bluetoothAuthorized: string | null,
/**
* 允许 App 使用摄像头的开关
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: Android平台:表示没有授予 `android.permission.CAMERA` 权限;iOS平台没有该值
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
*/
cameraAuthorized: string,
/**
* 允许 App 使用定位的开关
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: Android平台:表示没有授予 `android.permission.ACCESS_COARSE_LOCATION` 权限;iOS平台:表示没有在 `manifest.json -> App模块配置` 中配置 `Geolocation(定位)` 模块
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
*/
locationAuthorized: string,
/**
* 定位准确度。true 表示模糊定位,false 表示精确定位
* - reduced: 模糊定位
* - full: 精准定位
* - unsupported: 不支持(包括用户拒绝定位权限和没有在 `manifest.json -> App模块配置` 中配置 `Geolocation(定位)` 模块)
* @type 'reduced' | 'full' | 'unsupported'
*/
locationAccuracy: string | null,
/**
* 定位准确度(推荐使用 locationAccuracy 属性)。true 表示模糊定位,false 表示精确定位(仅 iOS 支持)
* @type boolean
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
*/
locationReducedAccuracy: boolean | null,
/**
* 允许 App 使用麦克风的开关
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: Android平台:表示没有授予 `android.permission.RECORD_AUDIO` 权限;iOS平台没有该值
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
*/
microphoneAuthorized: string,
/**
* 允许 App 通知的开关
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: Android平台没有该值;iOS平台:表示没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
*/
notificationAuthorized: string,
/**
* 允许 App 通知带有提醒的开关(仅 iOS 10.0+ 支持)
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: 没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "10.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
*/
notificationAlertAuthorized: string | null,
/**
* 允许 App 通知带有标记的开关(仅 iOS 10.0+ 支持)
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: 没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "10.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
*/
notificationBadgeAuthorized: string | null,
/**
* 允许 App 通知带有声音的开关(仅 iOS 10.0+ 支持)
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* - config error: 没有在 `manifest.json -> App模块配置` 中配置 `Push(推送)` 模块
* @type 'authorized' | 'denied' | 'not determined' | 'config error'
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "10.0",
* "uniVer": "√",
* "unixVer": "x"
* }
* }
* }
*/
notificationSoundAuthorized: string | null,
/**
* 允许读写日历的开关(仅微信小程序支持)
* - authorized: 已经获得授权,无需再次请求授权
* - denied: 请求授权被拒绝,无法再次请求授权;(此情况需要引导用户打开系统设置,在设置页中打开权限)
* - not determined: 尚未请求授权,会在App下一次调用系统相应权限时请求;(仅 iOS 会出现。此种情况下引导用户打开系统设置,不展示开关)
* @type 'authorized' | 'denied' | 'not determined'
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
*/
phoneCalendarAuthorized: string | null
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录