This is a small library designed to make it extremely simple for you to sync your iOS app’s ‘Documents’ folder’s files and subfolders to a folder on Dropbox.
Recently Dropbox brought out ‘sandbox’ api keys, which mean that your app only gets access to a single folder such as Dropbox/Apps/MyAppName. The idea is that this library is to be used with that setup.
Unfortunately the normal Dropbox API only gives primitive methods for getting metadata, uploading and downloading specific files – it doesn’t give you the simple ‘sync this folder now please’ functionality that you’re probably used to in the desktop variant. So this library hopes to deal with that.
It’s been extracted from an app I’ve been writing to help keep track of your cars' oil changes. You can see the app on http://apps.splinter.com.au. If you find this library useful, please buy my app, it may also be useful! Unless you live in appsterdam, sorry but I don’t have any apps for keeping track of the oil changes on your bicycle ;)
github.com/chrishulbert/CHDropboxSync
The idea is that in one view controller of your app, you’ll have a ‘sync’ button. In this controller, you’ll want a retain property to keep the syncer object alive. And this controller will be a delegate of the syncer, so it’ll know when to dealloc the syncer by nilling out the property.
Eg, in your view controller:
#import "CHDropboxSync.h" @property(retain) CHDropboxSync* syncer; @synthesize syncer; // Do the dropbox sync. This takes care of all user alerts - (void)mySyncButtonWasTapped { self.syncer = $new(CHDropboxSync); self.syncer.delegate = self; [self.syncer doSync]; } // Delegate callback from the syncer. You can dealloc it now. - (void)syncComplete { self.syncer = nil; } - (void)dealloc { self.syncer = nil; // Probably a good idea to do this ... [super dealloc]; }
Note that it is up to you to handle the normal Dropbox linking process.
You may choose to write your own syncer, eg you may wish it to be a background process instead of modal which i’ve chosen to. Or you may be curious about the two-way sync strategy. It’s very simple algorithm, so I wouldn’t recommend it for life-critical apps, but it does work well for my app:
MIT license – no warranties!
Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.
(Comp Sci, Hons - UTS)
Software Developer (Freelancer / Contractor) in Australia.
I have worked at places such as Google, Cochlear, Assembly Payments, News Corp, Fox Sports, NineMSN, FetchTV, Coles, Woolworths, Trust Bank, and Westpac, among others. If you're looking for help developing an iOS app, drop me a line!
Get in touch:
[email protected]
github.com/chrishulbert
linkedin