ios - 如何使用ImagePicker获取图片名称?我得到图像名称,但它只能在模拟器中使用,不能在实际设备中使用

标签 ios swift uiimagepickercontroller

我需要从照片库中选择图片名称。我正在使用 UIImagePicker 并且我得到了图像名称,但它只在模拟器中工作而不在实际设备中工作。

最佳答案

请试试这个: 在你的 UIImagePickerControllerDelegate 中:

   func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let asset = info[UIImagePickerControllerPHAsset] as? PHAsset {
        let assetResources = PHAssetResource.assetResources(for: asset)

        print(assetResources.first!.originalFilename)
    }

    dismiss(animated: true, completion: nil)
}

也许对你有帮助。谢谢。

关于ios - 如何使用ImagePicker获取图片名称?我得到图像名称,但它只能在模拟器中使用,不能在实际设备中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54089107/

相关文章:

ios - 使用 Swift 从字典数组创建对象数组

ios - Ionic 框架 ion-scroll pinch to zoom 在 iOS 上会导致图像模糊。

ios - 重构圈复杂度大于 10 的 switch 语句

swift - 如何将 NSArray<NSInteger> 或 NSData 转换为 UnsafeMutablePointer<UInt8> 并返回 Swift?

iOS UI 旋转器在处理后台线程时卡住

objective-c - iOS8 中的相机旋转和 OverlayView

ios - 为什么字符串添加需要这么长时间来构建?

ios - CGRect 调用中的 Swift 额外参数 "width"

ios - NSInternalInconsistencyException : The specified modal presentation style doesn't have a corresponding presentation controller

ios - 使用 AFnetworking 上传图像没有任何响应