使用 Dropbox iOS API 和 NSDate 下载或上传文件不起作用
我正在使用 Dropbox iOS API 在不同设备之间同步。使用以下代码,我尝试比较文件修改的日期以下载/上传较新的文件。问题是,它只是下载,从不上传。有什么提示吗?
- (void)dropboxAuth {
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] link];
}
else {
NSString *filename = @"NotesList.plist";
NSString *destDir = @"/";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *address = [documentsDir stringByAppendingPathComponent:@"NotesList.plist"];
[[self restClient] loadMetadata:@"/"];
if([[NSFileManager defaultManager] fileExistsAtPath:address]) {
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:address error:&error];
NSDate *fileDate =[dictionary objectForKey:NSFileModificationDate];
if ([[fileDate earlierDate:self.metaData.lastModifiedDate]isEqualToDate:fileDate]) {
[self.restClient loadFile:[NSString stringWithFormat: @"%@/%@", destDir, filename]
intoPath:address];
NSLog(@"Downloading");
}
else if ([[self.metaData.lastModifiedDate earlierDate:fileDate] isEqualToDate:self.metaData.lastModifiedDate]) {
[[self restClient] uploadFile:filename toPath:destDir fromPath:address];
NSLog(@"Uploading");
}
}
}
}
I am using the Dropbox iOS API to sync between different devices. Using the following code, I am trying to compare the dates when the file was modified to either download/upload the newer file. The problem is, that it is just downloading and never uploading. Any hints?
- (void)dropboxAuth {
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] link];
}
else {
NSString *filename = @"NotesList.plist";
NSString *destDir = @"/";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *address = [documentsDir stringByAppendingPathComponent:@"NotesList.plist"];
[[self restClient] loadMetadata:@"/"];
if([[NSFileManager defaultManager] fileExistsAtPath:address]) {
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:address error:&error];
NSDate *fileDate =[dictionary objectForKey:NSFileModificationDate];
if ([[fileDate earlierDate:self.metaData.lastModifiedDate]isEqualToDate:fileDate]) {
[self.restClient loadFile:[NSString stringWithFormat: @"%@/%@", destDir, filename]
intoPath:address];
NSLog(@"Downloading");
}
else if ([[self.metaData.lastModifiedDate earlierDate:fileDate] isEqualToDate:self.metaData.lastModifiedDate]) {
[[self restClient] uploadFile:filename toPath:destDir fromPath:address];
NSLog(@"Uploading");
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可疑的:
这总是评估为 true,这对我来说意味着
self.metaData.lastModifiedDate
等于fileDate
或fileDate
始终是两个日期中较早的一个。老实说,我什至无法解析这些条件。如果您尝试以其他方式评估它会发生什么?像这样,例如:
另外,如果日期相等,我想你两者都不想做,对吧?
This is suspect:
This is always evaluating to true, which means to me either that
self.metaData.lastModifiedDate
is equal tofileDate
or thatfileDate
is always the earlier of the two dates.Honestly, I'm having trouble even parsing these conditionals. What happens if you try evaluating it another way? like this, for instance:
Also, if the dates are equal, I assume you want to do neither, right?