Dropbox ios sync api:readData不要等待

时间:2013-12-11 10:07:46

标签: ios sync dropbox

我正在使用readData将zip文件与服务器同步,但程序不会等待下载zip更改。这是我的代码:

enter DBPath *newPath = [[DBPath root] childPath:@"decoupe.zip"];
DBError *dbError;
DBFile *dbFile = [[DBFilesystem sharedFilesystem] openFile:newPath    error:nil];
NSFileHandle *fileHandle = [dbFile readHandle:&dbError];
NSData *fileData = [dbFile readData:&readError];
[fileData writeToFile:@"/Users/walid/Documents/ikksTestSynchAPI/ikksTestSynchAPI/decoupe.zip" atomically:YES]; here

执行不等待下载新的zip文件,但如果我运行我的程序2或3次,则会下载新的zip文件,并且会影响zip文件的大小。

如何确保程序等待下载?

2 个答案:

答案 0 :(得分:0)

在Sync API中,所有读取都在文件的缓存副本上运行(当存在缓存版本时)。要更新到该文件的最新版本,您需要打开该文件,设置一个观察者,以便在文件更改时得到通知,等待文件的同步状态为isCached标志为真,然后调用update更新到该文件的最新版本。

有关示例,请参阅the "observers" section of the iOS tutorial

答案 1 :(得分:0)

我想我可以等待下载:while (!dbFile.newerStatus.cached) { [NSThread sleepForTimeInterval:1.0f]; NSLog(@"sleep "); }我可以等DBFileSystem在程序开头下载元数据,因为下载没有在第一次运行时触发,我想这是因为DBFileSystem没有信息(在dropbox中更新的文件)