- An account for Dropbox.
- Create (Sign up) your app and get the App keys at https://www.dropbox.com/developers/apps
- Download the Dropbox API at https://www.dropbox.com/developers/releases
- The Source Code could be downloaded here.
2. Start the project
Create an new Navigation-based Application. There is no need to check the Use Core Data for storage option if you don’t intend to use one.
Then integrate the Dropbox API.
(1). Right-click on your project in the group tree in the left pane
(2). Select Add -> Existing Files...
(3). Navigate to where you uncompressed the Dropbox SDK and select the DropboxSDK subfolder
(4). Select "Copy items into destination group's folder"
(5). Make sure "Recursively create groups for any added folders" is selected
(6). Press Add button
(7). Find the Frameworks folder in your app's group tree in the left pane
(8). Make sure the framework Security.framework is added to your project
(9). If not, right-click on Frameworks and select Add -> Existing Frameworks...
(10). Select Security.framework from the list and select Add
(11). Build your application. At this point you should have no build failures or
This is what it looks like this after you have taken the steps above to include the API.
Now we are ready to start using the Dropbox API.
Open the Dropbox_TutorialAppDelegate.m add the following codes.
These codes init the Dropbox link session with the app keys we just applied for.
4.Build the Main Interface and Hook up.
To keep things simple, we are not going to use any additional xib files. Go ahead and edit the RootViewController. It should look like this after added all the components we need.
Let’s initialize the view’s title and create an “Add” button on the navbar.
Next, in your header file, create a IBOutlet to your Table View and the Activity Indicator. We are going to use the table view for show the items we download from Dropbox and the activity indicator to indicate Dropbox operation is in progress.
5. Maintain the DBRestClient
In order to call Dropbox API, you need to implement the DBRestClientDelegate protocol and create a DBRestClient.
Add the following to your header file.
Also should define the getter method of restClient in .m file
Next, use DBSession has linked in ViewDidLoad to determine if there is already a session. If not, have Dropbox show a login window.
Go ahead and implement delegates for DBLoginController. In this tutorial there is no need to do anything.
6. Init the app
Let’s create a mutable array to store the datasource.
Call Dropbox’s loadMetadata in the viewWillAppear.
This will Read all the filename (include folder) into a mutable array and make it the tableview dataSource.
In loadMetadata delegate, we will populate the table with the filenames and folder names contained in the metadata.
Let’s test the app with what we got so far. When you launch the app and log into your Dropbox account, you will see something like the following:
7. Main functions of the app
Now we are ready to implement the core functionalities of our app. If you recall, previously we have made it so the app will read all your files in your Dropbox folder and list it in the table view. Now we will make it so when you press the Upload button, it will collect the data, write them into a plist file and upload it. If you press the Download button, it will look for the same file you just uploaded, download it and replace the current tableview data. Just how a normal Backup operation should behave right?
Let’s declare the functions in the header file.
Implement a help function to get the document path to the file we are saving to Dropbox account.
Pay attention to the two underlined functions on how we implement upload and download. When the upload or download operation is complete, it will call its corresponding delegate.
And the error handling, we will show the relevant information in an alert view. You may decide to do differently for your own apps.
Now let’s test our Upload/Download feture. We are going to add a button to add a random line of text (in this case, the current date time) to our table view
For the kick of it, we will implement the swipe-delete behavior for the table view.
And that’s it! Run the app, add a few lines of texts by pressing the Add button. Press the upload and download button to verify things work as they should. As you can see, Dropbox has made it very easy for you to back up and restore you information. Go Dropbox!
Dropbox API calls require connectivity and take time to complete. Be sure to display indication that the operation is underway and account for situation in which your user's device does not have connectivity.
Most Dropbox's API calls are asynchronous/non-blocking which means it won’t wait until the uploading or downloading is finished. Instead, will tell the request queue to add the task, then directly proceed to the next line of code. So the only way to react to things is to implement their respective delegates such as uploadedFile, downloadedFile, etc.