如何获得上传进度?

时间:2015-10-22 07:33:47

标签: ios progress drive

我使用Google官方文档为云端硬盘上传文件,但不知道如何上传进度以获取。官方文档说

Listening to the download progress

enter image description here

1 个答案:

答案 0 :(得分:0)

使用此功能将文件上传到驱动器并收听进度:

GTLServiceDrive *driveService = ...;
NSString *title = @"hello.txt";
NSString *content = @"Hello world";
NSString *mimeType = @"text/plain";

GTLDriveFile *metadata = [GTLDriveFile object];
metadata.title = title;

NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:metadata
                                                   uploadParameters:uploadParameters];
GTLServiceTicket *uploadTicket = [driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
                                                     GTLDriveFile *updatedFile,
                                                     NSError *error) {
    if (error == nil) {
        NSLog(@"File %@", updatedFile);
    } else {
        NSLog(@"An error occurred: %@", error);
    }
}];


[uploadTicket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long totalBytesWritten, unsigned long long totalBytesExpectedToWrite)
 {
     // progress here
 }];