iOS相册权限、相机权限、麦克风权限

相册权限 iOS8之后加入了PhotoKit,使用需要

#import

  • 权限类型
typedef NS_ENUM(NSInteger, PHAuthorizationStatus) { PHAuthorizationStatusNotDetermined = 0, // 未询问用户是否授权 PHAuthorizationStatusRestricted, // 未授权,例如家长控制 PHAuthorizationStatusDenied, // 未授权,用户拒绝造成的 PHAuthorizationStatusAuthorized// 已授权}

  • 权限检测
PHAuthorizationStatus photoAuthStatus = [PHPhotoLibrary authorizationStatus]; if (photoAuthStatus == PHAuthorizationStatusNotDetermined) {// 未询问是否授权 可以用下面的请求授权方法询问用户 }else if(photoAuthStatus == PHAuthorizationStatusRestricted || photoAuthStatus == PHAuthorizationStatusDenied) {// 未授权 }else{// 已授权 }

  • 请求授权
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { if (status == PHAuthorizationStatusAuthorized) { // 用户同意授权 }else { // 用户拒绝授权 }

相机&麦克风权限 首先

#import

其次 【iOS相册权限、相机权限、麦克风权限】相机对应AVMediaTypeVideo
麦克风对应AVMediaTypeAudio
  • 权限类型
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) { AVAuthorizationStatusNotDetermined = 0,// 未询问用户是否授权 AVAuthorizationStatusRestricted,// 未授权,例如家长控制 AVAuthorizationStatusDenied,// 未授权,用户拒绝造成的 AVAuthorizationStatusAuthorized// 已授权}

  • 权限检测
AVAuthorizationStatus videoAuthStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (videoAuthStatus == AVAuthorizationStatusNotDetermined) {// 未询问用户是否授权 }else if(videoAuthStatus == AVAuthorizationStatusRestricted || videoAuthStatus == AVAuthorizationStatusDenied) {// 未授权 }else{// 已授权 }

  • 请求授权
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {if (granted){// 用户同意授权}else {// 用户拒绝授权}}];



转: http://www.jianshu.com/p/b4fbc57c84b0

    推荐阅读