ios - 图像选择器在模拟器上崩溃

标签 ios swift

我在 Xcode 7.3 上制作了一个应用程序。今天我安装了 XCode8 并更改了一些代码然后当我在模拟器上点击照片库按钮时我看到了这个崩溃。在此之后,我试过 iPhone 6,效果很好。我不知道为什么。我需要开发应用程序,但我不能。只是因为模拟器错误。这太有趣了。

这是崩溃屏幕:

the crash screen

这是我的照片库代码:

@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/

相关文章:

ios - 在 App Store 上传后更改我的应用程序名称?

ios - Swift函数参数命名

swift - F# 异步 HTTP 请求 - 解析 JSON 响应

ios - Swift 在运行时获取 `Scheme Name or Swift Compiler - Custome Flags` 值

ios - UIButton的点击 Action ?

ios - 如何确保在文本字段中仅选择选择器数据

iphone - 如何在自定义单元格的 initWithStyle : method? 中获取 UITableView 的宽高

ios - 在不重新加载整个表的情况下更新 UITableView 中的特定行

ios - 显示 ViewControllerB 并关闭 ViewControllerA

swift - 服务器端 Swift Vapor - 模型继承