iOS 相册权限

相册权限–iOS 8.0之后

导入头文件@import Photos;

检查是否有相册权限

PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary authorizationStatus];

switch (photoAuthorStatus) {

case PHAuthorizationStatusAuthorized:

  NSLog(@"Authorized");

  break;

case PHAuthorizationStatusDenied:

  NSLog(@"Denied");

  break;

case PHAuthorizationStatusNotDetermined:

  NSLog(@"not Determined");

  break;

case PHAuthorizationStatusRestricted:

  NSLog(@"Restricted");

  break;

default:

  break;

}

![Uploading 144446-b8aca7ba38c5f8c0_695906.png …]获取相册权限

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

if (status == PHAuthorizationStatusAuthorized) {

  NSLog(@"Authorized");

}else{

  NSLog(@"Denied or Restricted");

}

}];

相机和麦克风权限

导入头文件@import AVFoundation;

检查是否有相机或麦克风权限

AVAuthorizationStatus AVstatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];//相机权限

AVAuthorizationStatus AVstatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];//麦克风权限

switch (AVstatus) {

case AVAuthorizationStatusAuthorized:

  NSLog(@"Authorized");

  break;

case AVAuthorizationStatusDenied:

  NSLog(@"Denied");

  break;

case AVAuthorizationStatusNotDetermined:

  NSLog(@"not Determined");

  break;

case AVAuthorizationStatusRestricted:

  NSLog(@"Restricted");

  break;

default:

  break;

}

获取相机或麦克风权限

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {//相机权限

if (granted) {

  NSLog(@"Authorized");

}else{

  NSLog(@"Denied or Restricted");

}

}];

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {//麦克风权限

if (granted) {

  NSLog(@"Authorized");

}else{

  NSLog(@"Denied or Restricted");

}

}];

发布了94 篇原创文章 · 获赞 7 · 访问量 16万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览