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