iOS 11 UIImagePickerController不显示隐私警报 - 如何强制显示权限对话框?

时间:2017-10-09 10:30:55

标签: objective-c swift3 ios11 xcode9 info.plist

我选择带有UIImagePickerController的照片时,我的商店拒绝显示隐私对话框。 我尝试了一个不同的项目,并在下面粘贴了我的代码,仍然没有得到任何隐私警报。

用户点击按钮选择照片,显示相机胶卷列表,可以挑选照片。一切正常,除了此操作之前的警报,要求用户允许操作不显示。

在应用提交时,没有任何错误或警告,只有应用审核小组拒绝让应用通过不显示提醒。

如何在访问照片库之前强制应用显示隐私提醒?

- (IBAction)pickAction:(id)sender {

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.delegate = self;
    [self presentViewController:imagePickerController animated:YES completion:nil];

}

<key>NSPhotoLibraryUsageDescription</key>
    <string>To pick photos for analysis</string>

我使用Swift3尝试了一个全新的项目,并且没有使用以下代码获得任何隐私/权限警告对话框:

    var imagePicker = UIImagePickerController()

    @IBAction func btnClicked() {

        if UIImagePickerController.isSourceTypeAvailable(.savedPhotosAlbum){
            print("Button capture")

            imagePicker.delegate = self
            imagePicker.sourceType = .savedPhotosAlbum;
            imagePicker.allowsEditing = false

            self.present(imagePicker, animated: true, completion: nil)
        }
    }

    func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
        self.dismiss(animated: true, completion: { () -> Void in

        })

//        imageView.image = image
    }

1 个答案:

答案 0 :(得分:1)

iOS 11引入了新的“照片”框架,其中包含可以明确请求用户权限的照片库对象:

你必须这样使用:

import Photos
class ViewController: UIViewController {
    override func viewDidLoad() {
        PHPhotoLibrary.requestAuthorization { (status) in
            switch status {
            case .authorized:
                print("authorized")
            case .denied:
                print("denied")
            default:
                print("default")
            }
        }
    }
}