在iOS中下载进度

时间:2014-05-14 05:53:56

标签: ios objective-c cocoa-touch sockets

当我们知道iPhone设备时,我们可以使用" ifaddrs"监控用户的数据。参考此链接:" iPhone Data Usage Tracking/Monitoring",但如何监控iOS中当前进程的下载数据?

1 个答案:

答案 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