Simple drop in and go. Displaying and viewing the request metrics is already handled
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Swift 3.
For Swift 4 see the Swift4
branch
URLSessionMetrics is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "URLSessionMetrics"
OR
Drag URLSessionMetrics/Classes
folder into your project and add files.
Make sure your Network calls library conforms to the URLSessionTaskDelegate
.
Inform the shared MetricsManager
that metrics were collected
extension RequestManager: URLSessionTaskDelegate {
public func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
MetricsManager.shared.add(entry: metrics)
}
}
@interface NetworkingManager()
#ifdef __IPHONE_10_0
<NSURLSessionTaskDelegate>
#endif
... [other code] ...
@end
@implementation NetworkingManager
...
#ifdef __IPHONE_10_0
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics {
[[MetricsManager shared] addWithEntry:metrics];
}
#endif
dmiedema, [email protected]
URLSessionMetrics is available under the MIT license. See the LICENSE file for more info.