iOS 权限判断 跳转对应设置界面

相机权限

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 }

转载于:https://www.cnblogs.com/Free-Thinker/p/7112382.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值