Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从Google Drive下载文件时的下载进度状态?_Iphone_Ios_Objective C_Google Drive Api_Download - Fatal编程技术网

Iphone 从Google Drive下载文件时的下载进度状态?

Iphone 从Google Drive下载文件时的下载进度状态?,iphone,ios,objective-c,google-drive-api,download,Iphone,Ios,Objective C,Google Drive Api,Download,我可以从谷歌硬盘下载文件,但我想知道下载进度。有人能告诉我怎么做吗 我在下载文件时尝试了以下方法: NSString *downloadURL = [[self.driveFiles objectAtIndex:indexPath.row] downloadUrl]; GTMHTTPFetcher *fetcher = [self.driveService.fetcherService fetcherWithURLString:downloadURL]; filename=[[NSString

我可以从谷歌硬盘下载文件,但我想知道下载进度。有人能告诉我怎么做吗

我在下载文件时尝试了以下方法:

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]));
}];
编辑 我找到了一个简单得多的解决办法。有一个块将用于进度的回调:

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

如果不提供更多信息,很难回答这样的问题。您可以提供您使用的代码,也可以提供指向API等的链接。@NSAddict plz请检查更新代码以从google drive下载文件。。当文件正在下载时,我如何知道下载进度…添加了我的答案,希望如此helps@NSAddict我会实施并让你知道。。。Thanks@NSAddict我已经为全局字节总数声明了long int..但是我没有得到进展。。你能澄清我的疑问吗?不提供更多信息就很难回答这样的问题。您可以提供您使用的代码,也可以提供指向API等的链接。@NSAddict plz请检查更新代码以从google drive下载文件。。当文件正在下载时,我如何知道下载进度…添加了我的答案,希望如此helps@NSAddict我会实施并让你知道。。。Thanks@NSAddict我已经为全局字节总数声明了long int..但是我没有得到进展。。你能澄清我的疑问吗…但file.fileSize并不是每次都出现。有时它是空的。但是file.fileSize并不是每次都出现。有时它是空的。