美文网首页
ios 9+ 访问权限总结

ios 9+ 访问权限总结

作者: 4fbc4e24081a | 来源:发表于2017-08-29 16:05 被阅读0次

1.判断相册权限

导入<Photos/Photos.h>
+(BOOL)judgeIsHavePhotoAlbumAuthority {
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
        return NO;
    }
    return YES;
}];
}

请求打开相册
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        if (status == PHAuthorizationStatusAuthorized) {
            //授权成功
        } else {
            //授权失败
    }];

2.判断相机权限

导入<AVFoundation/AVFoundation.h>
+ (BOOL)judgeIsHaveCameraAuthority {
    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (status == AVAuthorizationStatusDenied || status ==AVAuthorizationStatusRestricted) {
        return NO;
    }
    return YES;
}

请求使用相机
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
        if (granted) {
            //授权成功
        } else {
           //授权失败
        }
    }];

3.判断麦克风权限

导入<AVFoundation/AVFoundation.h>
+ (BOOL)judgeIsHaveRecordAuthority {
    AVAudioSessionRecordPermission status = [[AVAudioSession sharedInstance] recordPermission];
    if (status == AVAudioSessionRecordPermissionDenied) {
        return NO;
    }
    return YES;
}

请求使用麦克风
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
        if (granted) {
            //授权成功
        } else {
           //授权失败
        }
    }];

4.判断通讯录权限

导入<AddressBook/AddressBook.h>
+ (BOOL)judgeIsAddressBookAuthority {
      CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
        if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
            return NO;
        }
        return YES;
}

5.判断定位权限

导入<CoreLocation/CoreLocation.h>
+ (BOOL)judgeIsHaveLocationAuthority {
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    BOOL enabled = [CLLocationManager locationServicesEnabled];
    if (!enabled || status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted ) {
        return NO;
    }
    return YES;
}

6.判断日历权限

导入<EventKit/EventKit.h>
+ (BOOL)judgeIsHaveCalendarAuthority {
    EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
    if (status == EKAuthorizationStatusDenied || status == EKAuthorizationStatusRestricted) {
        return NO;
    }
    return YES;
}

请求打卡日历
 EKEventStore *eventStore = [[EKEventStore alloc] init];
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
         if (granted) {
            //授权成功
        } else {
           //授权失败
        }
    }];

7.判断蓝牙权限

+(BOOL)judgeIsHaveBluetoothAuthority {
    CBPeripheralManagerAuthorizationStatus status = [CBPeripheralManager authorizationStatus];
    if (status == CBPeripheralManagerAuthorizationStatusDenied || status == CBPeripheralManagerAuthorizationStatusRestricted) {
        return NO;
    }
    return YES;
}

注意在Plist文件中添加对应的权限说明

屏幕快照 2017-08-29 下午4.04.22.png

相关文章

  • ios 9+ 访问权限总结

    1.判断相册权限 2.判断相机权限 3.判断麦克风权限 4.判断通讯录权限 5.判断定位权限 6.判断日历权限 7...

  • 2019-06-17

    iOS上线被拒 --权限问题 --总结 当时改访问权限 忘记写相机权限了 在工程中info.plist添加对...

  • ios访问权限总结

    Face ID权限 Privacy - Face ID Usage Description 蓝牙权限 Privac...

  • 相册相机访问

    判断相册访问权限 iOS 8 之前 iOS 8之后 两者结合即是 判断相机访问权限 iOS7之前都可以访问相机,i...

  • iOS各种访问权限总结

    麦克风访问(AVAudioSession) 权限查看 权限请求 相机访问(AVCaptureDevice) 权限查...

  • iOS11最新隐私信息访问列表

    在iOS11中,隐私权限配置又发生了改变,将原来的相册访问权限分开了,现在有读写两种权限。 iOS11访问权限列表...

  • 2018-08-08

    iOS开发 iOS10访问权限的配置 麦克风权限:Privacy - Microphone Usage Descr...

  • iOS11最新隐私信息访问描述

    最近发现在iOS11中,隐私权限配置又发生了改变,将原来的相册访问权限分开了,现在有读写两种权限。 iOS11访问...

  • iOS 访问权限的配置

    参考 iOS11访问相册权限变更问题

  • iOS相册管理

    iOS相册访问 相关框架 相册权限管理 摄像头权限管理 获取权限后调用UIImagePickerControlle...

网友评论

      本文标题:ios 9+ 访问权限总结

      本文链接:https://www.haomeiwen.com/subject/njgodxtx.html