How to use background mode for Google Drive service in Objective-C

According to google-api-objectivec-client documentation library:

Requests made from any thread can be called back to the background thread by providing a background queue, as in this example:

service.delegateQueue = [[NSOperationQueue alloc] init]; 

When a delegate queue is specified, there is no requirement that the loop loop be executed on the thread executing the request.

But that will not work. Handlers are executed on the main thread.

Question:

How do I tell Google Drive to execute handlers in the background thread?

code snippet to play

Podfile:

 pod 'GTMOAuth2' pod 'GoogleAPIClient/Drive' 

Somewhere in the app:

 #import "GTLDrive.h" #import "GTMOAuth2Authentication.h" ... - (void) applicationDidFinishLaunching:(NSNotification *) aNotification { service = [[GTLServiceDrive alloc] init]; service.retryEnabled = YES; service.authorizer = _authorizer //from GTMOAuth2WindowController service.delegateQueue = [[NSOperationQueue alloc] init]; GTLDriveFile * tempadFolder = [GTLDriveFile object]; folder.name = @"folder-name"; folder.mimeType = @"application/vnd.google-apps.folder"; GTLQueryDrive * query = [GTLQueryDrive queryForFilesCreateWithObject: folder uploadParameters: nil]; [service executeQuery: query completionHandler: ^(GTLServiceTicket * ticket, GTLDriveFile * updatedFile, NSError * error) { if ([NSThread isMainThread]) { NSLog(@"This is a main thread!"); } } } 
+5
source share
1 answer

This bug has been fixed in this commit and released in GoogleAPIClient 1.0.2 .

So far, the code is working in accordance with the documentation:

Requests made from any thread can be called back to the background thread by providing a background queue, as in this example

 service.delegateQueue = [[NSOperationQueue alloc] init]; 
+3
source

Source: https://habr.com/ru/post/1246370/


All Articles