Dropbox iOS Core API - 在单独的线程中使用 DBRestClient

Dropbox iOS Core API - Working with DBRestClient in separate thread

我在应用程序中使用 Dropbox iOS api,需要上传应用程序在本地生成的文件。当应用程序生成一个文件时,它被插入一个队列(一个单独的线程),我需要 DBRestClient 在后台将它发送到 Dropbox;但不幸的是 DBRestClient 需要一个 ViewController 委托(我没有在我的上下文中;是一个通用的 NSObject class),当我调用上传文件方法时似乎没有任何反应。

谁能帮帮我?

调用 uploadFile 方法后,应调用其中一个委托方法来为您提供响应:

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath from:(NSString*)srcPath 
        metadata:(DBMetadata*)metadata;
- (void)restClient:(DBRestClient*)client uploadProgress:(CGFloat)progress 
        forFile:(NSString*)destPath from:(NSString*)srcPath;
- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error;
// [error userInfo] contains the sourcePath

这些你实现了吗?

如果是这样,有几件事可能会导致您的委托方法不被调用:

  1. 您的其余客户端为零或正在过早释放(例如,由 ARC)。
  2. 您正在没有 运行 循环的后台线程中进行调用。
  3. 你应该回调的委托方法有错字。不幸的是,如果 SDK 找不到要调用的委托方法,它不会警告您;它只是在没有告诉任何人的情况下完成。

根据您的描述,第二个可能相关,在这种情况下这可能会有所帮助:

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16-SW1