Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloud Sync for App Developers

Cloud Sync for App Developers

Mobile applications need to provide an amazing user experience across multiple platforms, devices, and even offline. Even though saving data in cloud storage is becoming ubiquitous on the web, it's still difficult to manage syncing, storage, and caching on mobile devices. In this session, you'll learn how Dropbox approaches these challenges and explore the developer tools available on the Dropbox platform.

Apps World, February 5, 2014
http://www.apps-world.net/northamerica/agenda/tracks/developer-world

Leah Culver

February 06, 2014
Tweet

More Decks by Leah Culver

Other Decks in Programming

Transcript

  1. • Sync across devices • Backup data • User identification

    • Offline access and sync Mobile app challenges
  2. Dropbox for your mobile apps • Cross-platform (Android, iOS, HTTP)

    • Users’ own Dropbox account • Caching, sync, and conflict resolution
  3. Dropbox APIs Files • Drop-ins: lightweight chooser / saver •

    Core API: HTTP REST-ish API • Sync API: file system-like interface ! Data • Datastore API: structured data
  4. Trigger the Chooser - (void)didPressChoose { DBChooser *chooser = [DBChooser

    defaultChooser]; ! [chooser openChooserForLinkType:DBChooserLinkTypePreview fromViewController:self completion:^(NSArray *results) { if ([results count]) { // Process results } else { // User cancelled } }]; }
  5. Chooser Returns: • link - preview or direct • thumbnails

    - for photo and video • file name, icon, and size
  6. Core API • REST-ish, OAuth 2.0, JSON • Android, iOS,

    OS X, Python, Ruby, Java, PHP • Community-supported libraries for C#, JavaScript, Perl, etc. HTTP API for files
  7. Permissions • App folder
 Permission to a specific folder !

    • File types
 Permission to a class of files (e.g. images) ! • Full Dropbox
 Permission to everything
  8. Sync API • Files for your app in your user’s

    Dropbox • Store and sync photos, videos, files, etc. • SDKs handle offline caching and syncing • Notifications of changes
  9. Add record on iOS DBTable *table = [self.store getTable:@"tasks"]; NSDictionary

    *newTask = @{@"name": @"Buy milk"}; [table insert:newTask]; [self.store sync:nil];
  10. List table DBDatastore *store = [DBDatastore openDefaultStoreForAccount:account error:nil]; DBTable *table

    = [store getTable:@"tasks"]; self.tasks = [table query:@{@"done": @NO} error:nil];
  11. Listen for changes [self.store addObserver:self block:^() { if (weakSelf.store.status &

    DBDatastoreIncoming) { NSDictionary *changes = [weakSelf.store sync:nil]; // Do something… }); }];
  12. • Local changes cached when offline • Syncs deltas with

    server when online • Automatically merge changes Offline / online syncing
  13. • Changes as objects (deltas) • Client sends delta(s) with

    “parent revision” • Server rejects a delta if parent revision doesn’t match • Server sends list of deltas to catch up • Client resolves conflict, sends new delta Conflict resolution
  14. • Changes to different records commute • Deletions win •

    Changes to the same field are merged Conflict resolution
  15. Customizable per-field: • Remote (default) - server wins • Local

    - client wins • Max - greater value wins • Min - lesser value wins • Sum - adds differences together Conflict resolution
  16. • Cross-platform SDKs • Both files and data • Users’

    own Dropbox • Handles offline access, sync, and conflict resolution Dropbox APIs