如何在Objective C中为Google Drive服务使用后台队列

kis*_*eno 5 multithreading background objective-c google-drive-api

根据文件谷歌-API的ObjectiveC客户端库:

通过提供后台队列,可以在后台线程上回调从任何线程进行的查询,如下例所示:

service.delegateQueue = [[NSOperationQueue alloc] init];
Run Code Online (Sandbox Code Playgroud)

指定委托队列时,不需要在执行查询的线程上运行运行循环.

但是,它不起作用.处理程序仍在主线程上执行.

题:

如何告诉Google Drive服务在后台线程上执行处理程序?

要重现的代码段

Podfile:

pod 'GTMOAuth2'
pod 'GoogleAPIClient/Drive'
Run Code Online (Sandbox Code Playgroud)

申请中的某个地方:

#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!");
                                             } 
                                         }
}
Run Code Online (Sandbox Code Playgroud)