【发布时间】:2013-03-07 09:16:22
【问题描述】:
我在我的应用程序中使用 GoogleDrive API 从我的应用程序上传文件。到目前为止,我成功并找到了上传所有类型文件的好结果。
我关注Google example上传文件。
我正在尝试在上传时显示进度,具体取决于文件大小。我在谷歌给出的示例代码中经历了很多课程,但没有太多结果。
获取文件上传进度的步骤:
我在 GTLServices.m 中找到了以下方法
- (void)setUploadProgressBlock:(GTLServiceUploadProgressBlock)block {
[uploadProgressBlock_ autorelease];
uploadProgressBlock_ = [block copy];
if (uploadProgressBlock_) {
// As above, we need the fetcher to call us back when bytes are sent.
SEL sentDataSel = @selector(objectFetcher:didSendBytes:totalBytesSent:totalBytesExpectedToSend:);
[[self objectFetcher] setSentDataSelector:sentDataSel];
}
}
之后在 MyViewController.m 中这样写
[self.driveService setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long numberOfBytesRead, unsigned long long dataLength) {
NSLog(@"uploading");
}];
在 NSLog 之上永远不会因此而被原谅,因为我无法获取上传的数据字节。通过调试,我发现 uploadProgressBlock_ 总是显示为零。这可能是我的块处理程序没有被执行的原因。
如果我在解决问题时犯了任何错误,请建议我。 如果有人知道将数据字节上传到谷歌驱动器以获取文件,请建议我。您的建议对我的工作更有用。
提前致谢。
采纳我们的建议的综合答案:
这是获取上传进度信息的代码
GTLServiceTicket *uploadTicket= [self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFile *updatedFile,NSError *error)
{
if (error == nil)
{
[self.delegate completedFileUploadingToGoogleDrive];
NSError *fileDeletionError=nil;
[[NSFileManager defaultManager] removeItemAtPath:absalutePath error:&fileDeletionError];
} else
{
[self.delegate errorOccoredWhileUploadingToGoogleDrive:error];
}
}];
[uploadTicket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long totalBytesWritten, unsigned long long totalBytesExpectedToWrite) {
[self.delegate uploadedFileInfoInKB:(float)totalBytesExpectedToWrite/1024 and:(float)totalBytesWritten/1024];
}];
编码愉快!!
【问题讨论】:
-
嗨,阿杰我需要你的帮助,我已经完成了谷歌集成,我已经成功地将音频文件上传到谷歌我需要在将音频文件上传到谷歌驱动器时显示进度条如果你知道这个概念建议我我该怎么做?
-
@Ravindhiran 请查看我已编辑的问题并给出答案代码。
-
+1 它工作正常,谢谢 ajay...
标签: iphone ios objective-c ipad google-drive-api