1

我可以从 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];
4

1 回答 1

4

编辑


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

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]));
}];
于 2013-08-26T12:26:16.250 回答