我正在使用phimagecachingmanager获取phasset的图像。我需要使用opportunistic
模式,以便首先加载可用的低分辨率图像,然后随着完整分辨率可用,它被加载。
由于某种原因,我不断收到以下警告,低分辨率图像不会加载。仅当从iCloud获取最高分辨率时,图像才会加载。
警告:
"First stage of an opportunistic image request returned a non-table format image, this is not fatal, but it is unexpected."
我在做什么错?
let imageRequestOptions = PHImageRequestOptions()
imageRequestOptions.isNetworkAccessAllowed = true
imageRequestOptions.deliveryMode = .opportunistic
let imageCachingManager = PHCachingImageManager()
imageCachingManager.requestImage(for: asset , targetSize: PHImageManagerMaximumSize, contentMode: .aspectFill, options: imageRequestOptions) { (image, infoDict) in
DispatchQueue.main.async {
if self.myImageView.identifierTag == asset.localIdentifier {
self.myImageView.image = image
}
}
}
imageCachingManager.requestImage(for: asset , targetSize: PHImageManagerMaximumSize, contentMode: .aspectFill, options: imageRequestOptions) { (image, infoDict) in
DispatchQueue.main.async {
if self.myImageView.identifierTag == asset.localIdentifier {
self.myImageView.image = image
}
}
}
您将最大尺寸设置为图像大小。更改
targetSize: PHImageManagerMaximumSize
to
targetSize: CGSize(width: asset.pixelWidth, height: asset.pixelHeight)
或指定图像大小,例如cgsize(使用:150,高度:150),除非您要由于内存耗尽而爆炸设备。
PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init];
option.synchronous = YES;
``
将synchronous 属性设置为YES