我正在寻找某种方法来检查文件何时在 Dropbox 上更新以告知用户。我发现最好的是属于 Sync API 的代码片段,它观察是否有任何变化:
// First, create a file for you to change
DBPath *path = [[DBPath root] childPath:@"change-me.txt"];
self.file = [[DBFilesystem sharedFilesystem] createFile:path error:nil];
// Next, register for changes on that file
[self.file addObserver:self block:^() {
// This block will be called every time your file changes
// if newerStatus is not nil, it means a newer version is available
DBFileStatus *newerStatus = file.newerStatus;
if (newerStatus) {
if (!newerStatus.cached) {
NSLog(@"newerStatus.cached == NO; this means the file downloading");
} else {
// Update to the newly available version and print it out
[file update:nil];
NSLog(@"The file is done downloading: %@", [file readString:nil]);
}
}
}];
有任何想法吗?我实际上是想添加 Sync api 只是为了使用此功能,但我不认为添加两个 Dropbox SDK 是正确的解决方案。