相机权限

1.1 使用说明

  1. 在合适的地方导入#import <AVFoundation/AVFoundation.h>
  2. 使用AVAuthorizationStatus类获取当前权限状态
  3. 在没有权限的情况下弹出alertView提示跳转。

1.2 代码示例

  • 权限判断
#import <AVFoundation/AVFoundation.h>
...
// 相机权限判断
- (void)getPhotoAuthorizationStatus
{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted) {
// 没有权限。弹出alertView
[self showAlert];
}else{
//获取了权限,直接调用相机接口
} }
  • 弹出alertView
- (void)showAlert
{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"相机权限未开启"
message:@"相机权限未开启,请进入系统【设置】>【隐私】>【相机】中打开开关,开启相机功能"
delegate:nil
cancelButtonTitle:@"取消"
otherButtonTitles:@"立即开启", nil]; @weakify(self);
[[alertView rac_buttonClickedSignal] subscribeNext:^(NSNumber *buttonIndex) {
@strongify(self);
if ([buttonIndex isEqualToNumber:@1]) {
#ifdef __IPHONE_8_0
//跳入当前App设置界面,
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
#else
//适配iOS7 ,跳入系统设置界面
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"prefs:General&path=Reset"]];
#endif
}
}];
[alertView show];
}

1.3 参数说明

  • 当前权限状态
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
AVAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
AVAuthorizationStatusRestricted, // 此应用程序没有被授权访问的照片数据。可能是家长控制权限
AVAuthorizationStatusDenied, // 用户已经明确否认了应用程序访问
AVAuthorizationStatusAuthorized // 用户已经授权应用访问相机
}
  • 跳转到系统设定界面的字段
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
AirplaneModeOn— prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date& Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General— prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE iCloud
Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music VolumeLimit— prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
SoftwareUpdate— prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI
Setting—prefs:root=INTERNET_TETHERING

注意:需要info中,添加 URL Schemes为 prefs的url

相册权限

1.1 使用说明

  1. 在合适的地方导入#import <AssetsLibrary/AssetsLibrary.h>
  2. 使用ALAuthorizationStatus类获取当前权限状态
  3. 在没有权限的情况下弹出alertView提示跳转。

1.2 代码示例

代码如下所示,alertView如相机权限中所示.

//相册权限判断
- (void)getAlbumAuthorizationStatus
{
ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];
if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
// 没有权限
[self showAlert];
}else{
// 已经获取权限
} }

1.3 参数说明

typedef NS_ENUM (NSInteger, ALAuthorizationStatus) {
kCLAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
kCLAuthorizationStatusRestricted, // 此应用程序没有被授权访问的照片数据。可能是家长控制权限
kCLAuthorizationStatusDenied, // 用户已经明确否认了这一照片数据的应用程序访问
kCLAuthorizationStatusAuthorized // 用户已经授权应用访问照片数据
} CLAuthorizationStatus;

定位权限

1.1 使用说明

  1. 在合适的地方导入#import <CoreLocation/CLLocation.h>
  2. 使用[CLLocationManager authorizationStatus]获取当前权限状态
  3. 在没有权限的情况下弹出alertView提示跳转。

1.2 代码示例

代码如下所示,alertView如相机权限中所示.

- (void)servicesEnabled
{
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) {
// 没有权限,
[self alertAuth];
}
}

1.3 参数说明

typedef NS_ENUM(int, CLAuthorizationStatus) {

 kCLAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
kCLAuthorizationStatusRestricted, // 受限制的,非用户行为,此应用程序没有被授权访问的照片数据。
kCLAuthorizationStatusDenied, / 用户已经明确否认了这一应用程序访问
kCLAuthorizationStatusAuthorizedAlways 定位服务授权状态已经被用户允许在任何状态下获取位置信息。
kCLAuthorizationStatusAuthorizedWhenInUse 定位服务授权状态仅被允许在使用应用程序的时候。
kCLAuthorizationStatusAuthorized NS_ENUM_DEPRECATED(10_6, NA, 2_0, 8_0, "Use kCLAuthorizationStatusAuthorizedAlways") __TVOS_PROHIBITED __WATCHOS_PROHIBITED = kCLAuthorizationStatusAuthorizedAlways
}

iOS 权限判断 跳转对应设置界面的更多相关文章

  1. iOSapp内跳转到设置界面

    从app内跳转到设置界面的代码如下: NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIAp ...

  2. iOS之访问权限以及跳转到系统界面

    iOS开发中有时候有这样的需求:当用户设置不允许访问照片.麦克风和相机等系统权限的时候,这时需要直接跳转到系统的隐私界面进行设置. 判断是否开启权限 前面已经说过,我们需要在用户不允许访问的时候跳转, ...

  3. android判断当前网络状态及跳转到设置界面

    今天,想做这个跳转到网络设置界面, 刚开始用 intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); 不料老是出现settings.Wirele ...

  4. iOS应用内跳转系统设置相关界面的方法

    在iOS开发中,有时会有跳转系统设置界面的需求,例如提示用户打开蓝牙或者WIFI,提醒用户打开推送或者位置权限等.在iOS6之后,第三方应用需要跳转系统设置界面,需要在URL type中添加一个pre ...

  5. android中 检查网络连接状态的变化,无网络时跳转到设置界面

    1:在AndroidManifest.xml中加一个声明 <receiver android:name="NetCheckReceiver">    <inten ...

  6. android检查网络连接状态的变化,无网络时跳转到设置界面

    在AndroidManifest.xml中加一个声明<receiver android:name="NetCheckReceiver"> <intent-filt ...

  7. iOS10 openURL方法跳转到设置界面

    问题 在iOS10之前,跳转到系统设置界面的某个指定界面的方式如下: //打开定位服务界面 NSURL*url=[NSURL URLWithString:@"prefs:root=Priva ...

  8. 在iOS应用程序中打开设备设置界面及其中某指定的选项界面

    摘自:http://stackoverflow.com/questions/8246070/ios-launching-settings-restrictions-url-scheme [[UIApp ...

  9. ios 导航push跳转方向设置

    CATransition* transition = [CATransition animation]; transition.type = kCATransitionPush;//可更改为其他方式 ...

随机推荐

  1. shell 杂集

    1.shell 相等比较注意 -eq 数字相等的比较 == 字符串相等的比较 2.== 和 = 的区别 == 可用于判断变量是否相等,= 除了可用于判断变量是否相等外,还可以表示赋值. = 与 ==  ...

  2. CI中的数据库操作以及AR连贯操作

    要使用CI中的数据库操作,首先我们应该在CI的 application/config/databass.php 文件中配置数据库信息,通常就是配置主机名,用户名,密码,数据库名,表前缀(dbprefi ...

  3. 上传图片到PHP服务器

    test_picture = function() { api.getPicture({ sourceType: 'library', encodingType: 'png', mediaValue: ...

  4. Python 3.8 新特性来袭

    Python 3.8 新特性来袭 Python 3.8是Python语言的最新版本,它适合用于编写脚本.自动化以及机器学习和Web开发等各种任务.现在Python 3.8已经进入官方的beta阶段,这 ...

  5. oracle AWR详解

    原文地址:https://blog.csdn.net/elvis_lfc/article/details/52326148 啥是AWR? =============================== ...

  6. JXLS生成excel并自定义单元格样式

    本人最近需要每天统计数据表,并每周一发送统计结果的邮件,所以写了个springboot老自动完成工作.项目地址为:https://github.com/707293891/springboot 其中某 ...

  7. yum 安装nginx(配置开机启动)

    yum install -y nginx 通过yum安装的时候提示下面的错误 [root@localhost yum.repos.d]# yum install nginx 已加载插件:fastest ...

  8. C++基础 (6) 第六天 继承 虚函数 虚继承 多态 虚函数

    继承是一种耦合度很强的关系 和父类代码很多都重复的 2 继承的概念 3 继承的概念和推演 语法: class 派生类:访问修饰符 基类 代码: … … 4 继承方式与访问控制权限 相对的说法: 爹派生 ...

  9. Virtual servers on a Raspberry Pi with the light weight OS virtualization system Docker!

    转自:http://www.hyggeit.dk/2014/02/virtual-servers-on-raspberry-pi-with.html Virtual servers on a Rasp ...

  10. hive 自定义函数(udf)

    1.解压hive的压缩包 2.新建java项目,将hive压缩包里面lib文件夹的jar包导入新建的项目 3.编写java程序 package udfdemo; import org.apache.h ...