我在 Xcode 7.3 上制作了一个应用程序。今天我安装了 XCode8 并更改了一些代码然后当我在模拟器上点击照片库按钮时我看到了这个崩溃。在此之后,我试过 iPhone 6,效果很好。我不知道为什么。我需要开发应用程序,但我不能。只是因为模拟器错误。这太有趣了。
这是崩溃屏幕:
这是我的照片库代码:
@IBAction func PhotoLibraryAction(_ sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
present(picker, animated: true, completion: nil)
}
@IBAction func CameraAction(_ sender: UIButton) {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .camera
present(picker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if var image = info[UIImagePickerControllerOriginalImage] as? UIImage {
ImageDisplay.image = image
}
dismiss(animated: true, completion: nil)
}
最佳答案
尝试将其添加到您的 plist 中:
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera.</string>
关于ios - 图像选择器在模拟器上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281071/