Developing with Objective Pascal

Part 13: Using Dropbox API with iOS and OS X


Contents

Introduction
Requirements
Get the SDK examples working
Parse the SDK header files
Get the Pascal example working


Introduction

While iOS 5.0 and OS X 10.7 added support for Apple's free iCloud service, iCloud is not available to earlier versions of iOS or OS X and, except for the iCloud Control Panel client for Windows, is generally not available for other platforms.

Adding support for iCloud to your iOS and OS X apps makes sense in many cases, but you may also want to consider adding support for an alternative like Dropbox when it's likely that some users will want to be able to share files with unsupported platforms. These notes describe how to do that.


Requirements


Get the SDK examples working

  1. Before you do anything else, make sure you can get the Dropbox SDK Objective C example programs working. Both the iOS and OS X SDKs include a DBRoulette example, which is a simple photo viewing app that downloads photos from the user's storage area for that app on the Dropbox server.

  2. Open one of the example projects in Xcode and run it (Product | Run). You'll get an error message that you haven't set the app key yet. To obtain an app key, log into your Dropbox account and create one:

    https://www.dropbox.com/developers/apps

    In iCloud terms, a Dropbox app key is similar to an iCloud "entitlement bundle identifier". In both cases, they can be used for more than one app that need to share the same files in the cloud. For example, you might have a lite version of your app and a full version - both could share the same app key/identifier so that a user who upgrades to the full version can continue to use files from the lite version. In our case, you can use the same app key for both the iOS and OS X example programs.

    Note that app names need to be unique - if the Dropbox site indicates that a name is already taken, try adding your initials to the app name.

  3. With both example programs, change the appKey, appSecret and root where indicated in the app delegate code. Also change the CFBundleURLSchemes key in the project's DBRoulette-Info.plist file. More information and an overview is here:

    https://www.dropbox.com/developers/start

    Note: Starting with the Setup step, make sure you have iOS selected from the dropdown menu.


Parse the SDK header files

Refer to this page for help with parsing the Dropbox header files and compiling the Pascal Dropbox units (Dropbox_iOS.pas and Dropbox_OSX.pas):

iOS_5_Parsing_Status.html


Get the Pascal example working

Download this file and unzip it:

Test6_DBiOS.zip

This is the start of a Pascal example program adapted from the iOS version of DBRoulette.

The Pascal example program can log in and log out of your Dropbox account. The Objective Pascal code is just a transliteration of the original Objective C code in DBRouletteAppDelegate.m and a bit from RootViewController.m. Adapting the remaining code in PhotoViewController.m that actually downloads the photos is left as an exercise for the reader.

To compile the Pascal example, you will need to do the following:


Copyright 2012 by Phil Hess.

macpgmr (at) fastermac (dot) net

First posted April 15, 2012; last edited May 9, 2013.