Added the metrics in the download token, make it easy to grab the information right in completion block (is this useful ?)
This commit is contained in:
parent
bb424d44fd
commit
ed894ecff5
|
@ -128,6 +128,11 @@ typedef SDImageLoaderCompletedBlock SDWebImageDownloaderCompletedBlock;
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, strong, nullable, readonly) NSURLResponse *response;
|
@property (nonatomic, strong, nullable, readonly) NSURLResponse *response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The download's metrics. This will be nil if download operation does not support metrics.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong, nullable, readonly) NSURLSessionTaskMetrics *metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
||||||
@property (nonatomic, strong, nullable, readwrite) NSURL *url;
|
@property (nonatomic, strong, nullable, readwrite) NSURL *url;
|
||||||
@property (nonatomic, strong, nullable, readwrite) NSURLRequest *request;
|
@property (nonatomic, strong, nullable, readwrite) NSURLRequest *request;
|
||||||
@property (nonatomic, strong, nullable, readwrite) NSURLResponse *response;
|
@property (nonatomic, strong, nullable, readwrite) NSURLResponse *response;
|
||||||
|
@property (nonatomic, strong, nullable, readwrite) NSURLSessionTaskMetrics *metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
|
||||||
@property (nonatomic, weak, nullable, readwrite) id downloadOperationCancelToken;
|
@property (nonatomic, weak, nullable, readwrite) id downloadOperationCancelToken;
|
||||||
@property (nonatomic, weak, nullable) NSOperation<SDWebImageDownloaderOperation> *downloadOperation;
|
@property (nonatomic, weak, nullable) NSOperation<SDWebImageDownloaderOperation> *downloadOperation;
|
||||||
@property (nonatomic, assign, getter=isCancelled) BOOL cancelled;
|
@property (nonatomic, assign, getter=isCancelled) BOOL cancelled;
|
||||||
|
@ -519,18 +520,30 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
_downloadOperation = downloadOperation;
|
_downloadOperation = downloadOperation;
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadReceiveResponse:) name:SDWebImageDownloadReceiveResponseNotification object:downloadOperation];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadDidReceiveResponse:) name:SDWebImageDownloadReceiveResponseNotification object:downloadOperation];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadDidStop:) name:SDWebImageDownloadStopNotification object:downloadOperation];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)downloadReceiveResponse:(NSNotification *)notification {
|
- (void)downloadDidReceiveResponse:(NSNotification *)notification {
|
||||||
NSOperation<SDWebImageDownloaderOperation> *downloadOperation = notification.object;
|
NSOperation<SDWebImageDownloaderOperation> *downloadOperation = notification.object;
|
||||||
if (downloadOperation && downloadOperation == self.downloadOperation) {
|
if (downloadOperation && downloadOperation == self.downloadOperation) {
|
||||||
self.response = downloadOperation.response;
|
self.response = downloadOperation.response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)downloadDidStop:(NSNotification *)notification {
|
||||||
|
NSOperation<SDWebImageDownloaderOperation> *downloadOperation = notification.object;
|
||||||
|
if (downloadOperation && downloadOperation == self.downloadOperation) {
|
||||||
|
if ([downloadOperation respondsToSelector:@selector(metrics)]) {
|
||||||
|
if (@available(iOS 10.0, tvOS 10.0, macOS 10.12, watchOS 3.0, *)) {
|
||||||
|
self.metrics = downloadOperation.metrics;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)cancel {
|
- (void)cancel {
|
||||||
@synchronized (self) {
|
@synchronized (self) {
|
||||||
if (self.isCancelled) {
|
if (self.isCancelled) {
|
||||||
|
|
Loading…
Reference in New Issue