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
@ -516,29 +516,33 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
|||||||
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
|
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
|
||||||
ASDisplayNodeAssertNotNil(request, @"request is required");
|
ASDisplayNodeAssertNotNil(request, @"request is required");
|
||||||
ASDisplayNodeAssertNotNil(completionBlock, @"completionBlock is required");
|
ASDisplayNodeAssertNotNil(completionBlock, @"completionBlock is required");
|
||||||
|
|
||||||
// Get the PHAsset itself.
|
// This is sometimes called on main but there's no reason to stay there
|
||||||
PHFetchResult *assetFetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[request.assetIdentifier] options:nil];
|
dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
|
||||||
if ([assetFetchResult count] == 0) {
|
// Get the PHAsset itself.
|
||||||
// Error.
|
PHFetchResult *assetFetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[request.assetIdentifier] options:nil];
|
||||||
completionBlock(nil, nil);
|
if ([assetFetchResult count] == 0) {
|
||||||
return;
|
// Error.
|
||||||
}
|
completionBlock(nil, nil);
|
||||||
|
return;
|
||||||
// Get the best image we can.
|
}
|
||||||
PHAsset *imageAsset = [assetFetchResult firstObject];
|
|
||||||
PHImageRequestOptions *options = [request.options copy];
|
PHAsset *imageAsset = [assetFetchResult firstObject];
|
||||||
if (options.deliveryMode == PHImageRequestOptionsDeliveryModeOpportunistic) {
|
PHImageRequestOptions *options = [request.options copy];
|
||||||
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
|
||||||
[[PHImageManager defaultManager] requestImageForAsset:imageAsset
|
options.synchronous = YES;
|
||||||
targetSize:request.targetSize
|
}
|
||||||
contentMode:request.contentMode
|
|
||||||
options:options
|
[[PHImageManager defaultManager] requestImageForAsset:imageAsset
|
||||||
resultHandler:^(UIImage *image, NSDictionary *info) {
|
targetSize:request.targetSize
|
||||||
completionBlock(image, info[PHImageErrorKey]);
|
contentMode:request.contentMode
|
||||||
}];
|
options:options
|
||||||
|
resultHandler:^(UIImage *image, NSDictionary *info) {
|
||||||
|
completionBlock(image, info[PHImageErrorKey]);
|
||||||
|
}];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock
|
- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user