将PHAsset转换为UIImage时出现了非致命但意外的错误

5

我正在使用这段代码将一个PHAsset转换为全尺寸的UIImage

func getOriginalAsset(asset: PHAsset, onComplete: @escaping (UIImage?, [AnyHashable: Any]?) -> ()) {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    option.isNetworkAccessAllowed = true

    manager.requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option) { (image, info) in
        onComplete(image, info)
    }
}

然而,每次我尝试运行此代码时,控制台都会给出以下警告:

[ImageManager] First stage of an opportunistic image request returned a non-table format image, this is not fatal, but it is unexpected

问题

  1. 为什么我会收到这个警告?

  2. 如何解决这个问题?

更新

尽管有警告,但当我运行这段代码时一切都正常。我只是不能容忍我的应用程序中出现任何警告/错误(也许我迟早得学会接受它)。


1
我不知道,但我不会担心它。请注意,对于您请求的每个图像,您最终将多次调用onComplete,因此这可能不是最佳架构。 - matt
1个回答

10

尝试使用这段代码,我添加了isSynchronous = true。你可以阅读这个文档isSynchronous

我将快速向您解释问题的原因。这个问题是由于操作直到图像结束才显示,并且你请求的大尺寸图像可能需要时间,所以在等待期间应该使用线程来等待获取图像的过程。

func getOriginalAsset(asset: PHAsset, onComplete: @escaping (UIImage?, [AnyHashable: Any]?) -> ()) {
        let manager = PHImageManager.default()
        let option = PHImageRequestOptions()
        option.isNetworkAccessAllowed = true
        option.isSynchronous = true 
        manager.requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option) { (image, info) in
            onComplete(image, info)
        }
}

这是错误的,因为将其设置为“isSynchronous”会使滚动变得缓慢,因为它需要等待每个图像先返回。 - sudoExclaimationExclaimation

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接