1

我正在使用Dropbox Sync API sdk它显示所有文件夹和文件,但我们无法下载文件我正在使用此代码:

  DBFilesystem *filesystem;
  DBFile *file = [_filesystem openFile:info.path error:nil];
   NSData *imagedata=[file readData:nil];
  [fileMan createFileAtPath:Image_filePath  contents:**data** attributes:nil];
  NSLog(@"flao=%d",[file writeData:imagedata error:nil]);
  // it return 1

我正在获取 NSData 但我无法存储在文档目录中。我检查以下链接但没有成功

Dropbox Sync API iOS 将文件复制到应用文档

与 DropBox API 和 iOS 同步数据

请帮我。

4

1 回答 1

1

Dropbox 需要时间来缓存文件,您可以设置一个块来监控缓存何时完成:

__block MyViewController *me = self;
[self.dropboxFile addObserver:self block:^() { [me monitorDropboxFile:@"Sync"]; }];

观察者内部:

- (void)monitorDropboxFile:(NSString *)caller
{
    if (self.dropboxFile.status.cached) {
        ; // Good to go, the file is cached
    } else {
        ; // download in progress
    }
}

或者,有一种更简单的方法,使用readHandle

(DBFile *)file;
// ...  
DBError *dbError;
NSFileHandle *fileHandle = [file readHandle:&dbError];

如 Dropbox API 标头中所述:

/** 返回文件的只读文件句柄。如果文件未缓存,则该方法将阻塞,直到文件被下载。
@return 如果文件可以读取或nil发生错误,则返回文件句柄。*/

返回时文件句柄已准备就绪。readHandle但是,如果应用程序在文件下载期间必须响应,您可能希望放入后台线程。

于 2013-10-31T03:33:03.350 回答