gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:53:07 28 4
gpt4 key购买 nike

根据 documentationgoogle-api-objectivec-client图书馆:

Queries made from any thread can be called back on a 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 for a run loop to be running on the thread that executes the query.

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

问题:

如何告诉 Google 云端硬盘服务在后台线程上执行处理程序?

要重现的代码片段

播客文件:

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

最佳答案

此错误已在 this commit 中修复并在 GoogleAPIClient 1.0.2 中发布。

目前代码的行为符合文档:

Queries made from any thread can be called back on a background thread by providing a background queue, as in this example

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

关于objective-c - 如何在 Objective C 中为 Google Drive 服务使用后台队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36393753/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com