ファイルをダウンロードするには、次のようにします。
GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:url];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error)
{
[data writeToFile:localFilePath atomically:YES];
}];
ファイルは正常にダウンロードされましたが、このようにするとダウンロードの進行状況を取得できません。
fetcher.downloadProgressBlock = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite)
{
NSLog(@"bytesWritten = %lld",bytesWritten);
NSLog(@"totalBytesWritten = %lld",totalBytesWritten);
NSLog(@"totalBytesExpectedToWrite = %lld",totalBytesExpectedToWrite);
};
私は何を間違っていますか?
私は実用的な解決策を見つけました。
float totalBytesExpectedToWrite = [file.size floatValue]; //file - it's GTLDriveFile to download
[fetcher setReceivedProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten)
{
NSLog(@"Download progress - %.0f",(totalBytesWritten * 100)/totalBytesExpectedToWrite);
}];