iOS7之后要求的权限检查, 使用AVAuthorizationStatus进行判断
相机权限代码如下:
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted) {
// 相机不被允许或者被限制
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请在iPhone的“设置-隐私-相机”选项中,允许该APP访问您的相机。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
}
else if (authStatus == AVAuthorizationStatusNotDetermined) {
// 没有设置过权限, 会弹出询问窗口
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
// 允许相机权限
}
}];
}
else if (authStatus == AVAuthorizationStatusAuthorized) {
// 允许使用相机
}
相册权限代码如下:
ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];
余下代码同相机部分