mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
Request and receive images in background queue
This commit is contained in:
parent
ffa0829fc9
commit
f6fe3b07d8
@ -517,6 +517,8 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
||||
ASDisplayNodeAssertNotNil(request, @"request is required");
|
||||
ASDisplayNodeAssertNotNil(completionBlock, @"completionBlock is required");
|
||||
|
||||
// This is sometimes called on main but there's no reason to stay there
|
||||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
|
||||
// Get the PHAsset itself.
|
||||
PHFetchResult *assetFetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[request.assetIdentifier] options:nil];
|
||||
if ([assetFetchResult count] == 0) {
|
||||
@ -525,11 +527,12 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the best image we can.
|
||||
PHAsset *imageAsset = [assetFetchResult firstObject];
|
||||
PHImageRequestOptions *options = [request.options copy];
|
||||
if (options.deliveryMode == PHImageRequestOptionsDeliveryModeOpportunistic) {
|
||||
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
|
||||
if (options.deliveryMode == PHImageRequestOptionsDeliveryModeHighQualityFormat) {
|
||||
// Without this flag the result will be delivered on the main queue, which is pointless
|
||||
// But synchronous -> HighQualityFormat so we only use it if high quality format is specified
|
||||
options.synchronous = YES;
|
||||
}
|
||||
|
||||
[[PHImageManager defaultManager] requestImageForAsset:imageAsset
|
||||
@ -539,6 +542,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
||||
resultHandler:^(UIImage *image, NSDictionary *info) {
|
||||
completionBlock(image, info[PHImageErrorKey]);
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user