注意:此方法只对ios7以上的系统有用,刚才用“我查查”试了下,如果是在ios6的系统的话就直接崩溃了,况且ios6上也没有“设置--隐私--相机” 那一项
if(IOS7)
{
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusNotDetermined)
{
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.delegate = self;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.allowsEditing = NO;
[self presentViewController:pickerController animated:YES completion:^{
}];
}
else
{
return;
}
}];
}
else if (authStatus == AVAuthorizationStatusDenied)
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle: nil
message:@"请在iPhone的\"设置-隐私-相机\"选项中,允许xx访问你的相机。"
delegate:nil
cancelButtonTitle: @"确定"
otherButtonTitles:nil, nil];
[alert show];
}
else if (authStatus == AVAuthorizationStatusAuthorized)
{
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.delegate = self;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.allowsEditing = NO;
[self presentViewController:pickerController animated:YES completion:^{
}];
}
else if (authStatus == AVAuthorizationStatusRestricted)
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle: nil
message:@"请在iPhone的\"设置-隐私-相机\"选项中,允许xx访问你的相机。"
delegate:nil
cancelButtonTitle: @"确定"
otherButtonTitles:nil, nil];
[alert show];
}
}
else
{
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.delegate = self;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.allowsEditing = NO;
[self presentViewController:pickerController animated:YES completion:^{
}];
}

被折叠的 条评论
为什么被折叠?



