iphone - 从Google云端硬盘下载文件时的下载进度状态?

标签 iphone ios objective-c google-drive-api download

我可以从Google驱动器下载文件,但是我想知道下载进度。谁能告诉我该怎么做?

我已经尝试过下载文件:

NSString *downloadURL = [[self.driveFiles objectAtIndex:indexPath.row] downloadUrl];
GTMHTTPFetcher *fetcher = [self.driveService.fetcherService fetcherWithURLString:downloadURL];
filename=[[NSString alloc] init];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error)
 {
     GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];
     NSLog(@"\n\n\n\n\n");
     NSLog(@"This is File Size=====>%@",file.fileSize);
     NSLog(@"This is file Name===>%@",file.title);

     if(file.downloadUrl!= nil)
     {
         if (data!=nil)
         {
             filename=file.title;

             NSArray *paths =    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
             NSString *documentsDirectory = [paths objectAtIndex:0];
             documentsDirectory = [[paths   objectAtIndex:0]stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",filename]];
             [data writeToFile:documentsDirectory atomically:YES];

最佳答案

编辑

我找到了一个更简单的解决方案。有一个块将用于进度的回调:

GTMHTTPFetcher *fetcher =
    [self.driveService.fetcherService fetcherWithURLString:downloadURL];
GTLDriveFile *file = [driveFiles objectAtIndex:indexPath.row];

[fetcher setReceivedDataBlock:^(NSData *data) {
    NSLog(@"%f%% Downloaded", (100.0 / [file.fileSize longLongValue] * [data length]));
}];

关于iphone - 从Google云端硬盘下载文件时的下载进度状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18443564/

相关文章:

ios - 在 iOS7 的 UITableView 中显示/隐藏新值?

iphone - 将 UIWebView 根 URL 重新映射到 [[NSBundle mainBundle] bundleURL]

ios - 证书和临时资料问题

ios - 将一个数据库中的表复制到另一个数据库

ios - 在 iOS11 上,如何让 UIToolbar 调整所有项目的大小以适应?

ios - 当我将 UITextField 与 resignFirstResponder 结合使用时,它最多不是 1 个数字

objective-c - OpenSSL x509 证书 : Add Extension with X509_add1_ext_i2d()

ios - iPad 屏幕尺寸返回错误值

iphone - iOS : detect UIImageView for UITouch Events

ios - UITableViewCell textLabel 使文本垂直对齐在顶部 &estimatedHeightForRowAtIndexPathUITableViewCell 在选定的单元格上跳转