永远不会在Google API for ios中上传数据进度 [英] Never getting uploading data progress in google API for ios
问题描述
我在我的应用程序中使用GoogleDrive API从我的应用程序上传文件。到目前为止,我成功地找到了上传所有类型文件的良好结果。
I am using GoogleDrive API in my application to upload files from my application. So far I succeeded and finding good results for uploading all types of files.
我跟着 Google示例上传文件。
我试图在上传时显示进度,具体取决于文件大小。我在google给出的示例代码中经历了很多课程,但结果并不多。
I am trying to show the progress, dependent on file size, while uploading. I have gone through many classes in the google given example code but there isn't much result.
获取文件上传进度的步骤:
我在GTLServices.m中找到了以下方法
I have found below method In 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中写完这样的
After that in MyViewController.m written like this
[self.driveService setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long numberOfBytesRead, unsigned long long dataLength) {
NSLog(@"uploading");
}];
以上NSLog永远不会因为这个原因而无法获得上传的数据字节。通过调试,我发现 uploadProgressBlock _ 始终显示为nil。可能这是我的块处理程序没有被执行。
Above NSLog never getting excused because of this I am unable to get uploaded data bytes. By debugging I come across as uploadProgressBlock_ always showing nil. may be this resone my block handler not getting executed.
如果我有任何错误,请建议我。
如果任何人有想法将数据的字节上传到谷歌驱动器的文件请建议我。您的建议对我的工作更有用。
Please suggest me if I did any mistake to work it out. If any one have idea to get the bytes of data uploaded to google drive for a file please suggest me. Your suggestions are more useful to my work.
提前致谢。
合并答案我们的人建议:
以下是获取上传进度信息的代码
Here is the code to get upload progress information
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];
}];
快乐编码!!
推荐答案
我已经成功使用了上传块回调...将它分配给你从 executeQuery获得的
方法。 GTLServiceTicket
对象
I have succeeded in using the upload block callback... assign it to the GTLServiceTicket
object you obtain from the executeQuery
method.
示例:
GTLServiceTicket *uploadTicket = [self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *insertedFile, NSError *error)
{ // completion
}];
[uploadTicket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long totalBytesWritten, unsigned long long totalBytesExpectedToWrite)
{
// progress
}
这篇关于永远不会在Google API for ios中上传数据进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!