我尝试从图库中读取照片,但它会出现此错误。当我尝试模拟器时,我可以正确地拍摄这张照片,但不能使用个人手机。我想这是关于 Sandbox ,但我没有找到任何解决方案。 这与任何许可无关。
注意:此图片来自服务,我存储在照片库中,并将此路径保留在核心数据中。然后我尝试阅读这个网址。
答案 0 :(得分:-1)
您需要获得使用照片库的许可。 转到 Info.plist 并添加隐私权 - 照片库使用说明
您需要检查此权限:
func checkPermission() {
let authStatus = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
switch authStatus {
case .authorized:
self.displayUploadImageDialog(btnSelected: YOUR_BUTTON_HERE)
case .denied:
alertPromptToAllowCameraAccessViaSetting()
default:
break
}
}
func checkLibrary() {
let photos = PHPhotoLibrary.authorizationStatus()
if photos == .authorized {
switch photos {
case .authorized:
self.displayUploadImageDialog(btnSelected: YOUR_BUTTON_HERE)
case .denied:
alertPromptToAllowCameraAccessViaSetting()
default:
break
}
}
}
func alertPromptToAllowCameraAccessViaSetting() {
let alert = UIAlertController(title: "Error", message: "You are not allow accsess to camera and library", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .default))
alert.addAction(UIAlertAction(title: "Settings", style: .cancel) { (alert) -> Void in
UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!)
})
present(alert, animated: true)
}
答案 1 :(得分:-1)
Privacy - Photo Library Additions Usage Description
还在Info.plist中添加上述权限