2016-04-04 17 views
5

を背景キューを使用する方法:任意のスレッドから作ら<a href="https://github.com/google/google-api-objectivec-client" rel="noreferrer">google-api-objectivec-client</a>ライブラリの<a href="https://github.com/google/google-api-objectivec-client/wiki#threading" rel="noreferrer">documentation</a>によるObjective Cの中でGoogleドライブサービスの

クエリは、こののように、バックグラウンドのキューを提供することにより、バックグラウンドスレッドでコールバックすることができます例:

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

デリゲートキューが指定されている場合、クエリを実行するスレッドで実行ループを実行する必要はありません。

しかし、動作しません。ハンドラは依然としてメインスレッド上で実行されます。

質問:

バックグラウンドスレッドでハンドラを実行するためにGoogleドライブサービスを伝えるためにどのように?

Podfile再現するコードスニペット:どこかのアプリケーションで

pod 'GTMOAuth2' 
pod 'GoogleAPIClient/Drive' 

を:

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

答えて

3

このバグはthis commitで固定し、GoogleAPIClient 1.0.2にリリースされました。今コードについて

はマニュアルに従って動作します任意のスレッドから作ら

クエリは

service.delegateQueue = [[NSOperationQueue alloc] init]; 
この例のように、バックグラウンド待ち行列を提供することによって、バックグラウンドスレッドでコールバックすることができます
関連する問題