ios - 在真实设备上未授予访问照片库的权限

标签 ios swift

在我的应用中,用户应该有权访问照片库以选择应该在 ImageView 组件中显示的照片。

我正在使用以下代码来做到这一点:

@IBAction func selectPhotoButtonTapped(sender: AnyObject) {

    picker.allowsEditing = false
    picker.sourceType = .PhotoLibrary
    self.botonEnviar.hidden=false
    presentViewController(picker, animated: true, completion: nil)



}

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    dismissViewControllerAnimated(true, completion: nil)
}



func imagePickerController(
    picker: UIImagePickerController,
    didFinishPickingMediaWithInfo info: [String : AnyObject])
{
    let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    myImageView.contentMode = .ScaleAspectFit
    myImageView.image = resizeImage(chosenImage, newWidth: 1000)


    dismissViewControllerAnimated(true, completion: nil)


}

这在模拟器上运行良好,但在真实设备上,该应用无法访问设备的照片库。

我需要在应用中包含什么才能请求用户授予访问照片库的权限? 谢谢。

最佳答案

首先,检查您的设备设置 >> 您的应用程序 >> 权限。

关于ios - 在真实设备上未授予访问照片库的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35495422/

相关文章:

ios - “an ssl error has occurred and a secure connection to the server cannot be made” 仅在手机上连接到内部开发服务器

ios - 自动调整自定义 UITableViewCell 的大小

ios - 如何使 subview 调整大小为 UIScrollView ContentSize?

swift - 如何在 Swift 中用字符串进行文本到语音转换时产生 1-5 秒的小停顿?

ios - CLLocationManager 中 horizo​​ntalaccuracy 的平均精度是多少?

ios - 仅更改默认 UILabels 的 UIAppearance

ios - 如何在 Objective C 中处理数据库中的特殊字符?

ios - iOS 图像 UIButton 中的私有(private)字符串字段

ios - NSMethodSignature 和 NSInvocation 等价于 swift 2

ios - 用于多个字典键的 Swift 过滤器