为什么我无法使用UIImagePickerController访问照片库

5

enter image description here代码没有错误,但是在真实手机上测试后,甚至模拟器上也只显示一个锁定图像以及"This app does not have access to your photos or videos you can enable access in Privacy settings"(该应用程序无法访问您的照片或视频,在隐私设置中可以启用访问权限),但是当我转向设置时,我无法在隐私设置中找到我的应用程序。我做错了什么?

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.row == 0 {
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){

            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.allowsEditing = false


            let selectedSourceAction = UIAlertController(title: "What source do you want to access?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)

            let fromPhotoLibrary = UIAlertAction(title: "Photo Library", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction!) -> Void in
                imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

                self.presentViewController(imagePicker, animated: true, completion: nil)
        })
            let fromCamera = UIAlertAction(title: "Camera", style: UIAlertActionStyle.Default, handler: {(action: UIAlertAction!) -> Void in
                imagePicker.sourceType = UIImagePickerControllerSourceType.Camera

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

            let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)

            selectedSourceAction.addAction(fromPhotoLibrary)
            selectedSourceAction.addAction(fromCamera)
            selectedSourceAction.addAction(cancelAction)

            self.presentViewController(selectedSourceAction, animated: true, completion: nil)
        }


    }

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {


    imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
    imageView.contentMode = UIViewContentMode.ScaleAspectFit
    imageView.clipsToBounds = true

    dismissViewControllerAnimated(true, completion: nil)
}

前往设置 --> 隐私 --> 照片 --> 在您的应用上启用照片 - Maddy
@Maddy,当我第一次打开应用程序时,它没有提示我是否允许访问我的照片,也找不到刚安装的应用程序在隐私应用列表中。 - Xuewei Niu
@Maddy 但我另外创建了一个项目,输入相同的代码,它可以正常工作,我猜可能是在我的项目上出了问题。 - Xuewei Niu
1个回答

5

当你的应用程序的Info.plist文件包含一个键为“CFBundleDisplayName”的空字符串值时,这种错误可能会在IOS 9上发生。


谢谢,这解决了我近两天的问题,差点把我逼疯。真的很奇怪,试图显示UIImagePickerController时,它会默默地失败,没有任何错误提示。 - MC.
我使用了TOCropViewcontroller库,模拟器上弹出窗口正常,但在设备上没有弹出。有什么帮助吗? - Avijit Nagare

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接