Ios 如果已授予photolibrary权限,但未授予camera权限,则camera将打开并拍摄一张空白照片

Ios 如果已授予photolibrary权限,但未授予camera权限,则camera将打开并拍摄一张空白照片,ios,objective-c,uiimagepickercontroller,phphotolibrary,Ios,Objective C,Uiimagepickercontroller,Phphotolibrary,我已经拒绝了相机的许可,但之前已经获得了照片库的许可。但相机是用黑屏打开的。我可以看到拍照的选项。有没有办法不打开相机 我的代码是这样的 -(void)showImagePickerWithSoureType:(UIImagePickerControllerSourceType)type { if([UIImagePickerController isSourceTypeAvailable:type]) { pickerObj = [UIImagePickerCo

我已经拒绝了相机的许可,但之前已经获得了照片库的许可。但相机是用黑屏打开的。我可以看到拍照的选项。有没有办法不打开相机

我的代码是这样的

-(void)showImagePickerWithSoureType:(UIImagePickerControllerSourceType)type
{
    if([UIImagePickerController isSourceTypeAvailable:type])
    {
        pickerObj = [UIImagePickerController new];
        pickerObj.sourceType = type;
        UIViewController *topMostViewController = [CommonFunctions getTopMostViewControllerFromRootViewController:[CommonFunctions getAppDelegateObject].window.rootViewController];
        dispatch_async(dispatch_get_main_queue(), ^{
           [topMostViewController presentViewController:pickerObj animated:YES completion:NULL];
            pickerObj.delegate = self;
            pickerObj.editing = true;
            pickerObj.allowsEditing = true;
        });


        if([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusNotDetermined)
        {
            [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
                switch (status) {
                    case PHAuthorizationStatusAuthorized:
                        break;
                    case PHAuthorizationStatusRestricted:
                        [self imagePickerControllerDidCancel:pickerObj];
                        break;
                    case PHAuthorizationStatusDenied:
                        [self imagePickerControllerDidCancel:pickerObj];
                        break;
                    default:
                        break;
                }
            }];
        }
    }
}
试着这样做:

对于摄像头

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if(authStatus == AVAuthorizationStatusAuthorized)
    {
        [self accessCamera];
    }
    else if(authStatus == AVAuthorizationStatusNotDetermined)
    {

        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
         {
             if(granted)
             {
                 [self accessCamera];
             }
             else
             {
                 [self deniedCamera];
             }
         }];
    }
else
 {
            [self deniedCamera];
 }
对于照片库

PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];

if (status == PHAuthorizationStatusAuthorized) {
    [self accessPhotoLibrary];
}
else if (status == PHAuthorizationStatusNotDetermined) {

    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

        if (status == PHAuthorizationStatusAuthorized) {
            [self accessPhotoLibrary];
        }else {
            [self deniedPhotoLibrbary];
        }
    }];
}
else  {
    [self deniedPhotoLibrbary];
}
以及调用pickerView委托的方法

-(void)accessCamera{        


    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self presentViewController:picker animated:YES completion:NULL];
        });
}


-(void)accessPhotoLibrary{
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.allowsEditing = YES;
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self presentViewController:picker animated:YES completion:NULL];
        });

}
然后,您可以使用info方法从didFinishPickingMediaWithInfo获取图像。

尝试以下操作:

对于摄像头

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if(authStatus == AVAuthorizationStatusAuthorized)
    {
        [self accessCamera];
    }
    else if(authStatus == AVAuthorizationStatusNotDetermined)
    {

        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
         {
             if(granted)
             {
                 [self accessCamera];
             }
             else
             {
                 [self deniedCamera];
             }
         }];
    }
else
 {
            [self deniedCamera];
 }
对于照片库

PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];

if (status == PHAuthorizationStatusAuthorized) {
    [self accessPhotoLibrary];
}
else if (status == PHAuthorizationStatusNotDetermined) {

    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

        if (status == PHAuthorizationStatusAuthorized) {
            [self accessPhotoLibrary];
        }else {
            [self deniedPhotoLibrbary];
        }
    }];
}
else  {
    [self deniedPhotoLibrbary];
}
以及调用pickerView委托的方法

-(void)accessCamera{        


    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self presentViewController:picker animated:YES completion:NULL];
        });
}


-(void)accessPhotoLibrary{
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.allowsEditing = YES;
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self presentViewController:picker animated:YES completion:NULL];
        });

}
然后您可以通过
didFinishPickingMediaWithInfo
方法获取图像