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

时间:2015-08-08 09:04:29

标签: 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)
}

1 个答案:

答案 0 :(得分:5)

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