参考:https://blog.csdn.net/zhao15127334470/article/details/81216876
拍照
UIAlertAction * takePhoto = [UIAlertAction actionWithTitle:DKLang(@"拍照", @"拍照") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
NSString *aleartMsg = @"";
aleartMsg = @"请在\"设置 - 隐私 - 相机\"选项中,允许多客访问您的相机";
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:nil message:aleartMsg delegate:nil cancelButtonTitle:DKLang(@"OK", @"确定") otherButtonTitles:nil];
[alert show];
return;
}
//获取访问相机权限时,弹窗的点击事件获取
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
debugLog(@"允许了");
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
//判断是否有摄像头
if([UIImagePickerController isSourceTypeAvailable:sourceType])
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self; // 设置委托
imagePickerController.sourceType = sourceType;
imagePickerController.allowsEditing = NO;
//需要以模态的形式展示
[self presentViewController:imagePickerController animated:YES completion:^{
}];
}
} else {
debugLog(@"被拒绝了");
}
}];
}];
网友评论