int __block tip = 0;
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (!granted) {
tip = 1;
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
if (tip) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在“设置->隐私->相机” 设置本APP访问权限" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}
//判断来源是否为相机 Available 可捕获的
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; //来源相机
UIImagePickerController *picker = [[UIImagePickerController alloc]init]; //先初始化
picker.delegate = self;
//判断是否可以编辑
if (edit) {
picker.allowsEditing = YES; //是否可以编辑
}else{
picker.allowsEditing = NO;
}
picker.sourceType = sourceType; //设置图片的来源
[self presentViewController:picker animated:YES completion:nil];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在“设置->隐私->相机” 设置本APP访问权限" delegate:self cancelButtonTitle:@"确定"otherButtonTitles:nil, nil];
[alert show];
}