если разрешение фотобиблиотеки дано, а разрешение камеры не дано, то камера открывается и делает пустую фотографию

Я отказал в разрешении камеры, но ранее дал разрешение фотобиблиотеке. Но камера открывается с черным экраном. и я вижу возможность сделать фото. Есть ли способ не открывать камеру.

Мой код такой

-(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;
                }
            }];
        }
    }
}

person Divya Saraswati    schedule 02.08.2017    source источник


Ответы (1)


Попробуйте так:

Для камеры:

    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];
 }

Для PhotoLibrary:

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.

person Himanth    schedule 02.08.2017