I'm a little upset with the DropBox API. Everything is supposed to be simple and straightforward, but I still have to go through a simple and simple explanation of how to make simple synchronization.
I followed all the instructions that you can find in the readme that comes with the DropBox API. To test all this, I created two buttons to upload and download a file from or to DropBox. Files are located in the application's document folder.
This works great:
-(void) DBupload:(id)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"MyExample.txt"]; // NSError *error; [self.restClient uploadFile:@"MyExample.txt" toPath:@"/MyExamplePath" fromPath:filePath]; } -(void) DBdownload:(id)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents directory NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"MyExample.txt"]; NSError *error; [self.restClient loadFile:@"/myExamplePath/MyExample.txt" intoPath:filePath]; }
However, now I am wondering how to achieve simple synchronization. Right now, I can manually download and upload. But I need to sync:
- find out if the MyExample.txt file in my application folder or in my DropBox folder is later
- if txt in the App folder is later: drop it in the dropbox (overriding the old one), i.e. call my DBupload method
- if txt in the drop-down list is later: upload it to the application folder, i.e. call my DBdownload method
Maybe I'm just too dumb, but somewhere DropBox details, how to achieve this rather simple and direct task?
I know there is this , but actually it does not give any code samples.
Thanks for any suggestions.
EDIT
OK, so I decided that my first step would be to find out the last modified date of MyExample.txt, which is in the dropBox.
I wrote a wonderful method called DBsync in which I just put this command:
-(void) DBsync { [self.restClient loadMetadata:@"/myExamplePath"]; }
This calls the following method, which receives metadata. This was the suggested answer to this post, and I commented a bit on this so that it is clear what is happening (if such stupid people like me:
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata { NSLog(@"restClient:loadedMetadata function called"); NSEnumerator *e= [metadata.contents objectEnumerator];
I will post the next step as soon as I succeed ...