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");
}
}
}
}