避免在iOS 9.3.3中使用UIImagePickerController访问摄像头时显示两个权限警报



感谢您的阅读。

我在iOS 9.3.3版本中面临一个新问题,当第一次使用UIImagePickerController访问相机时。

默认情况下,苹果在iOS应用程序中第一次访问摄像头时显示权限警告,它的工作很好。

在拍完照片并点击使用按钮后,苹果会再显示一个提醒视图,并提示"应用程序想要访问照片"。

点击OK按钮,我没有得到选定的照片。这只是第一次发生。但这在其他版本中不会发生。

我知道这是不可能避免警报视图的iOS。但是有没有可能在拍照后抑制第二个警报视图呢?

有人能帮我一下吗?

请参阅以下代码:

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
            imagePickerController.delegate = self;
            imagePickerController.allowsEditing = NO;
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            [weakSelf.parent presentViewController:imagePickerController animated:YES completion:nil];
        } else {
            UIAlertController *alert = [UIAlertController
                                        alertControllerWithTitle:@"Camera is not available."
                                        message:nil
                                        preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *okAction = [UIAlertAction
                                        actionWithTitle:@"Ok"
                                        style:UIAlertActionStyleDefault
                                        handler:^(UIAlertAction *action)
                                        {
                                        }];

            [alert addAction:okAction];
            [self.parent presentViewController:alert animated:YES completion:nil];
        }
[self.parent presentViewController:importMenu animated:YES completion:nil];

这是你需要的代码(iOS 9及以上版本):

PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
switch (status) 
{
    case PHAuthorizationStatusAuthorized:
       //Write your customisation code
        break;
    case PHAuthorizationStatusNotDetermined:
    {
        [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus)
        {
            if (authorizationStatus == PHAuthorizationStatusAuthorized)
            {
                //Write your own code...
            }
            else
            {
                //Show alert view
            }
        }];
        break;
    }
    default:
        //Show alert view
        break;
}

最新更新