mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Restore artificial delay in Multiplex demo.
The change to ASBasicImageDownloader regressed the artificial network delay in the original demo code. Revert it.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
|
||||
|
||||
@interface ViewController () <ASMultiplexImageNodeDataSource, ASMultiplexImageNodeDelegate>
|
||||
@interface ViewController () <ASMultiplexImageNodeDataSource, ASMultiplexImageNodeDelegate, ASImageDownloaderProtocol>
|
||||
{
|
||||
ASMultiplexImageNode *_imageNode;
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
|
||||
|
||||
// multiplex image node!
|
||||
_imageNode = [[ASMultiplexImageNode alloc] initWithCache:nil downloader:[[ASBasicImageDownloader alloc] init]];
|
||||
// NB: we're using a custom downloader with an artificial delay for this demo, but ASBasicImageDownloader works too!
|
||||
_imageNode = [[ASMultiplexImageNode alloc] initWithCache:nil downloader:self];
|
||||
_imageNode.dataSource = self;
|
||||
_imageNode.delegate = self;
|
||||
|
||||
@@ -132,4 +133,50 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark ASImageDownloaderProtocol.
|
||||
|
||||
- (id)downloadImageWithURL:(NSURL *)URL
|
||||
callbackQueue:(dispatch_queue_t)callbackQueue
|
||||
downloadProgressBlock:(void (^)(CGFloat progress))downloadProgressBlock
|
||||
completion:(void (^)(CGImageRef image, NSError *error))completion
|
||||
{
|
||||
// if no callback queue is supplied, run on the main thread
|
||||
if (callbackQueue == nil) {
|
||||
callbackQueue = dispatch_get_main_queue();
|
||||
}
|
||||
|
||||
// call completion blocks
|
||||
void (^handler)(NSURLResponse *, NSData *, NSError *) = ^(NSURLResponse *response, NSData *data, NSError *connectionError) {
|
||||
// add an artificial delay
|
||||
usleep(1.0 * USEC_PER_SEC);
|
||||
|
||||
// ASMultiplexImageNode callbacks
|
||||
dispatch_async(callbackQueue, ^{
|
||||
if (downloadProgressBlock) {
|
||||
downloadProgressBlock(1.0f);
|
||||
}
|
||||
|
||||
if (completion) {
|
||||
completion([[UIImage imageWithData:data] CGImage], connectionError);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// let NSURLConnection do the heavy lifting
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
|
||||
[NSURLConnection sendAsynchronousRequest:request
|
||||
queue:[[NSOperationQueue alloc] init]
|
||||
completionHandler:handler];
|
||||
|
||||
// return nil, don't support cancellation
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)cancelImageDownloadForIdentifier:(id)downloadIdentifier
|
||||
{
|
||||
// no-op, don't support cancellation
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user