Added the URLSessionTaskMetrics support for downloader && operation, which can be used for network metrics
This commit is contained in:
parent
aa7ff6f060
commit
bb424d44fd
|
@ -498,6 +498,15 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
}
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) {
|
||||
|
||||
// Identify the operation that runs this task and pass it the delegate method
|
||||
NSOperation<SDWebImageDownloaderOperation> *dataOperation = [self operationWithTask:task];
|
||||
if ([dataOperation respondsToSelector:@selector(URLSession:task:didFinishCollectingMetrics:)]) {
|
||||
[dataOperation URLSession:session task:task didFinishCollectingMetrics:metrics];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDWebImageDownloadToken
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
@optional
|
||||
@property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask;
|
||||
@property (strong, nonatomic, readonly, nullable) NSURLSessionTaskMetrics *metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
|
||||
@property (strong, nonatomic, nullable) NSURLCredential *credential;
|
||||
@property (assign, nonatomic) double minimumProgressInterval;
|
||||
|
||||
|
@ -62,6 +63,12 @@
|
|||
*/
|
||||
@property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask;
|
||||
|
||||
/**
|
||||
* The collected metrics from `-URLSession:task:didFinishCollectingMetrics:`.
|
||||
* This can be used to collect the network metrics like download duration, DNS lookup duration, SSL handshake dureation, etc. See Apple's documentation: https://developer.apple.com/documentation/foundation/urlsessiontaskmetrics
|
||||
*/
|
||||
@property (strong, nonatomic, readonly, nullable) NSURLSessionTaskMetrics *metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
|
||||
|
||||
/**
|
||||
* The credential used for authentication challenges in `-URLSession:task:didReceiveChallenge:completionHandler:`.
|
||||
*
|
||||
|
|
|
@ -52,6 +52,8 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
|
|||
|
||||
@property (strong, nonatomic, readwrite, nullable) NSURLSessionTask *dataTask;
|
||||
|
||||
@property (strong, nonatomic, readwrite, nullable) NSURLSessionTaskMetrics *metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
|
||||
|
||||
@property (strong, nonatomic, nonnull) dispatch_queue_t coderQueue; // the queue to do image decoding
|
||||
#if SD_UIKIT
|
||||
@property (assign, nonatomic) UIBackgroundTaskIdentifier backgroundTaskId;
|
||||
|
@ -512,6 +514,10 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
}
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) {
|
||||
self.metrics = metrics;
|
||||
}
|
||||
|
||||
#pragma mark Helper methods
|
||||
+ (SDWebImageOptions)imageOptionsFromDownloaderOptions:(SDWebImageDownloaderOptions)downloadOptions {
|
||||
SDWebImageOptions options = 0;
|
||||
|
|
Loading…
Reference in New Issue