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

标签 ios

enter image description here没有错误,但是当我在真实手机上测试它时,即使在模拟中,它也只显示锁定图像和“此应用无法访问您的照片或视频,您可以在隐私设置中启用访问权限”但是当我转向设置 我在隐私设置中找不到我的应用程序。我哪里出错了?

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)
}

最佳答案

当您的应用程序的 Info.plist 文件包含一个键:具有空字符串值的“CFBundleDisplayName”时,此类错误可能会在 IOS 9 上发生。

关于ios - 为什么我无法使用 UIImagePickerController 访问照片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31891478/

相关文章:

ios - 在 iOS6 中获取用户个人资料图片?

ios - 无法在 iOS 上的 AFNETWORKING 中使用多部分 POST 上传视频

ios - 按下按钮时打开 Facebook 应用程序页面。 swift 5

ios - 单击按钮之前读取数据库信息

ios - UISegmentedControl 在 View Controller 之间切换

ios - 我如何在 Storyboard中使用 pdf 作为图像?

ios - Xcode 6.1.11 - 存档应用程序没有图标

ios - 如何从此JSON字典中检索数据?

ios - 无法在模拟器 : Xcode 6. 0.1 iOS 8 中运行应用程序

ios - 以 UIViewController 作为数据源的 UICollectionView