【问题标题】:Download Progress Status, when file is downloading from Google Drive?下载进度状态,何时从 Google Drive 下载文件?
【发布时间】:2013-08-26 12:00:00
【问题描述】:

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

我已经试过这个来下载文件:

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];

【问题讨论】:

  • 如果不提供更多信息,很难回答这样的问题。您可以提供您使用的代码,也可以提供指向 API 等的链接。
  • @NSAddict 请检查从谷歌驱动器下载文件的更新代码..当文件下载时我如何知道下载进度..
  • 添加了我的答案,希望对您有所帮助
  • @NSAddict 我会实施并让你知道...谢谢
  • @NSAddict 我已经声明了 long int 作为全球总字节数..但我没有得到进展..你能解决我的疑问吗...

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


【解决方案1】:

编辑


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

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]));
}];

【讨论】:

  • file.fileSize 并不是每次都来。有时是null
猜你喜欢
  • 1970-01-01
  • 2023-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 1970-01-01
  • 2021-10-24
  • 2021-09-22
相关资源
最近更新 更多