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!"); } } }
source share