问题来源: ios7及以后的系统自带二维码扫描库AVFoundation,但是若关闭相机对应用的隐私授权后,二维码扫描会造成应用闪退;
此时,需针对用户是否开相机隐私授权做相关判断;
[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
[UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
以上两个方法均无法实现判断,返回值均为yes,只能作为iPhone/ipod 是否有相机功能判断;
具体解决方法如下:
if(isIOS7Later) //isIOS7Later 是用来区分ios7及以后的系统;
{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus != AVAuthorizationStatusAuthorized)
{
//此处可以做相关提示及操作;
UIAlertView * tip = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您相机隐私授权尚未打开,若要打开请前往 设置-隐私-相机 中打开。" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[tip show];
[tip release];
return;
}
}