在负责网络的单身人士中,我创建了一个驱动服务实例:
self.service = [[GTLServiceDrive alloc] init];
[self.service setShouldFetchInBackground:YES];
在某些时候,我创建了一张上传给定文件的票证:
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithFileHandle:fileHandle MIMEType:kGDriveMimeType];
GTLDriveFile *newFile = [GTLDriveFile object];
newFile.title = @"123";
// keep the file inside event folder
GTLDriveParentReference *parentFolder = [GTLDriveParentReference object];
parentFolder.identifier = parentFolderId;
newFile.parents = @[parentFolder];
GTLQueryDrive *uploadQuery = [GTLQueryDrive queryForFilesInsertWithObject:newFile uploadParameters:uploadParameters];
GTLServiceTicket *serviceTicket = [self.service executeQuery:uploadQuery completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *uploadedFile, NSError *uploadError) {
if (completionHandler) {
completionHandler(uploadedFile, uploadError);
}
}];
[serviceTicket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long numberOfBytesRead, unsigned long long dataLength) {
CGFloat progress = (CGFloat)numberOfBytesRead / (CGFloat)dataLength;
if (progressHandler) {
progressHandler(progress);
}
}];
整个问题是,当我使用GTMHTTPFetcher
下载数据时,后台的工作仍在继续。使用GTLServiceTicket
上传时,应用在后台会暂停。我找不到任何属性让它在后台工作。我错过了什么吗?怎么做?
答案 0 :(得分:0)
我没有找到GTLServiceTicket
的任何合适的解决方案,所以我已经完成了自定义包装器,它正在收听UIApplicationDidEnterBackgroundNotification
并使用beginBackgroundTaskWithName:expirationHandler:
。