Sync with Dropbox Core API

375 Views Asked by At

I'm trying to implement syncing my iOS app's Documents directory with Dropbox, with the Core API. I just need very basic sync functionality, keeping the Documents directory the same as the App’s Dropbox directory.

Yet, I'm finding myself having to think about hard sync problems right off the bat, like checking for differences in files, figuring out how to determine if a local directory needs to be updated, allowing for external changes, etc. -- stuff that is pretty advanced and stuff that I thought the Dropbox SDK would abstract away.

It feels like I'm solving syncing problems and reinventing the wheel instead of focusing on my app.

It sounds like what I really need is the Sync API, but it's deprecated.

Is there a guide to implementing Sync behaviour withth the Core API or, failing that, is there a general-purpose guide to implementing sync with a cloud service?

1

There are 1 best solutions below

2
On BEST ANSWER

This is a relatively broad question, and the specifics will be very much dependant on each app. Dropbox doesn't offer a general guide for implementing sync like this, but I'll try to point to some useful resources.

First, you'll probably want to use the iOS Core SDK (download, tutorial). Alternatively, you can develop directly against the Core API HTTP endpoints.

When something changes locally in your app, you'll need to upload the new versions of the relevant files. The Dropbox API endpoints for uploading offer a few parameters that let you control overwrite/conflict behaviors:

https://www.dropbox.com/developers/core/docs#files_put

We recommend using parent_rev, in order to avoid accidentally overwriting and thus eventually losing data.

To know what changes happen remotely, you can use /delta (loadDelta in the iOS Core SDK):

https://blogs.dropbox.com/developers/2013/12/efficiently-enumerating-dropbox-with-delta/

For client-side apps, using /longpoll_delta is a good way to know when things change (i.e., to know when to call /delta):

https://blogs.dropbox.com/developers/2013/11/low-latency-notification-of-dropbox-file-changes/

That endpoint isn't currently implement in the iOS Core SDK though, but the SDK is open source, so you can modify it if/as necessary.