当我们知道iPhone设备时,我们可以使用" ifaddrs"监控用户的数据。参考此链接:" iPhone Data Usage Tracking/Monitoring",但如何监控iOS中当前进程的下载数据?
答案 0 :(得分:0)
使用NSURLSessionDownloadTask并实施它的委托
-(void)URLSession:(NSURLSession *)session
downloadTask:(NSURLSessionDownloadTask *)downloadTask
didWriteData:(int64_t)bytesWritten
totalBytesWritten:(int64_t)totalBytesWritten
totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
{
NSLog(@"%f / %f", (double)totalBytesWritten,
(double)totalBytesExpectedToWrite);
}
完整教程可在此处找到:http://www.raywenderlich.com/51127/nsurlsession-tutorial