npm i --save nativescript-advanced-permissions
- 版本:1.2.0
- GitHub:
- NPM: https://npmjs.net.cn/package/nativescript-advanced-permissions
- 下载
- 昨日:0
- 上周:3
- 上月:37
nativeScript-advanced-permissions
此插件是对Nathanael的nativescript-permissions插件的封装,同时提供与iOS权限匹配的API。
安装
描述您的插件安装步骤。理想情况下,它可能如下
tns plugin add nativescript-advanced-permissions
使用方法
目前要请求相机权限,我们使用它如下
import { hasCameraPermission, requestCameraPermission } from 'nativescript-advanced-permissions/camera';
// also supports 'nativescript-advanced-permissions/files';
// also supports 'nativescript-advanced-permissions/calendar';
// also supports 'nativescript-advanced-permissions/location';
if( !hasCameraPermission() ) {
requestCameraPermission().then((hasPermission) => {
if( hasPermission ) {
// do something cool
} else {
// don't do something
}
});
}
API
此插件已被分割成更小的 '子模块',使用时可以访问指定的权限。
我们目前包含的子模块有: files
、calendar
、location
、camera
对于每个子模块,我们遵循相同的命名规范: requestXPermission/hasXPermission
其中 x 是子模块名的首字母大写。
相机模块
使用方法
import { hasCameraPermission, requestCameraPermission } from 'nativescript-advanced-permissions/camera';
if( !hasCameraPermission() ) {
requestCameraPermission().then((hasPermission) => {
if( hasPermission ) {
// do something cool
} else {
// don't do something
}
});
}
API
函数 | 返回类型 | 描述 |
---|---|---|
hasCameraPermission() | 布尔值 | 返回应用程序是否有使用相机的权限 |
requestCameraPermission() | Promise |
请求用户允许相机权限,如果允许则返回一个真值Promise,如果不允许则返回一个假值 |
位置模块
使用方法
import { goToAppSettings } from 'nativescript-advanced-permissions/core';
import { hasLocationPermission, requestLocationPermission, isLocationEnabled } from 'nativescript-advanced-permissions/location';
if ( isLocationEnabled() ) {
if( !hasCameraPermission() ) {
requestCameraPermission().then((hasPermission) => {
if( hasPermission ) {
// do something cool
} else {
// don't do something
}
});
}
} else {
// tell the user to enable Location Services.
alert('Please Enable Location Settings...').then(() => goToAppSettings());
}
API
函数 | 返回类型 | 描述 |
---|---|---|
hasLocationPermission() | 布尔值 | 返回应用程序是否有使用位置服务的权限 |
requestLocationPermission() | Promise |
请求用户允许位置权限,如果允许则返回一个真值Promise,如果不允许则返回一个假值 |
isLocationEnabled() | 布尔值 | 返回设备上位置服务是否启用 |
日历模块
使用方法
import { hasCalendarPermission, requestCalendarPermission } from 'nativescript-advanced-permissions/calendar';
if( !hasCalendarPermission() ) {
requestCalendarPermission().then((hasPermission) => {
if( hasPermission ) {
// do something cool
} else {
// don't do something
}
});
}
API
函数 | 返回类型 | 描述 |
---|---|---|
hasCalendarPermission() | 布尔值 | 返回应用程序是否有使用日历的权限 |
requestCalendarPermission() | Promise |
请求用户允许日历权限,如果允许则返回一个真值Promise,如果不允许则返回一个假值 |
许可证
Apache许可证版本2.0,2004年1月
特别感谢!
感谢天才Nathaniel Anderson提供的Android权限插件,我在此插件中使用了它 Nativescript-Permissions