我正在尝试访问照片库以在 swift 4 中导入个人资料图像。
但是我收到了这个错误:
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
我以各种方式请求许可。
我尝试:
<key>NSPhotoLibraryUsageDescription</key>
<string>this permission for profile photo only</string>
和代码:
let imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
}
@objc func importUserImage() {
print("import driver")
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true)
}
我试试
<key>NSPhotoLibraryAddUsageDescription</key>
<string>this permission for profile photo only</string>
我什至尝试用代码来做到这一点
import UIKit
import Photos
import UserNotifications
class LoginViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
PHPhotoLibrary.requestAuthorization { (status) in
// cruch here
}
}
}
我删除了应用程序并重新安装它,仍然崩溃
我是不是忘记了什么?或者我做错了什么?
最佳答案
试试这个:
转到您的plist。在最顶部,应该显示信息属性列表已选择此选项。然后右键单击并添加行输入隐私 - 照片库添加使用说明,然后在其右侧有一个值列,需要您输入文本,这就是用户的内容等着瞧。我希望这有帮助!
关于ios - Swift 请求用户访问照片库的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53307475/