Related Posts Plugin for WordPress, Blogger...
This form does not yet contain any fields.

    Follow Me on Pinterest

    Our products are on iTunes!

     Nanaimo Studio

    Find us on Google+ 

     

    We are listed on: Dmegs Link Directory

    Blog Index
    404 page
    « Safari Books Online - a good idea with bad strategy | Main | Nerdracula »
    Friday
    Jan212011

    How to synchronize your app data using Dropbox API





    1. Preparation

     


     

    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

           warnings

     

    This is what it looks like this after you have taken the steps above to include the API.

     

    3. Configuration

     

    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!

     

    Notes

    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.

    PrintView Printer Friendly Version

    EmailEmail Article to Friend

    References (2)

    References allow you to track sources for this article, as well as articles that were written in response to this article.
    • Response
      How to synchronize your app data using Dropbox API - Our Blog - Nanaimo Studio
    • Response
      How to synchronize your app data using Dropbox API - Our Blog - Nanaimo Studio

    Reader Comments (11)

    Nice Tutorials´╝ü
    But I want to ask a question at thew method in
    -(NSString*)getDocumentPath
    which the "FILENAME" in the third line
    I just write in my project, but Xcode didn't know what it means...
    so I want to ask what's that mean, THX

    April 13, 2011 | Unregistered CommenterEn

    When I run this tutorial, should I have Dropbox installed on my Apple device?

    Also, I'm not able to see anything in the tableview. The program receives SIGABRT when I press ADD.
    Please help.

    May 6, 2011 | Unregistered CommenterNamratha

    Answering the previous question, I think it is the name of a file to be uploaded or downloaded so I think we're supposed to hardcode the filename.
    In the header file, we can have NSString *FILENAME = "myfile.ext";
    But, the problem is we can only do this for one file.

    May 6, 2011 | Unregistered CommenterNamratha

    Hi,
    I tried this tutorial but am getting the error while logging in. the error is "unable to login only the app owner can receive access token while this app is in development mode". Please help me to fox this issue.


    Thanks,
    little boy

    July 29, 2011 | Unregistered Commenterloganathan

    Useful link if you have issues building the project: http://roundwalk.blogspot.com/2012/03/importing-dropbox.html

    April 24, 2012 | Registered CommenterBoon Chew

    can't use Dropbox API

    I use Xcode4.3 and 5.1 simulator.

    Plese tell me how Dropbox API use on my version.

    Thanks,

    May 14, 2012 | Unregistered CommenterYuu

    I have implemented Dropbox; all is well until I have to check for connectivity. I am about to try the Apple sample code Reachability You many not be familiar with that code (nor am I but get the idea this checks for wi-fi connectivity). Do you have another suggestion? Thank you.

    August 10, 2012 | Unregistered CommenterChris

    Download link is not working ... Would you fix this please ?

    January 7, 2013 | Unregistered CommenterVakul Saini

    why doesnt your blog show images that you are using

    August 23, 2013 | Unregistered Commenteranonymous

    Hi,
    Thanks for valuable information. I want know more about licensing. I proceed my explanation with an Example . Say I have an app on store which has used dropbox apis to upload some file or so,which is generating me revenue .Then should I pay percentage to DropBox corp ?please help me out.

    Thanks in advance.
    Pradeep

    December 4, 2013 | Unregistered CommenterPradeep

    I can't see the images here.

    January 20, 2014 | Unregistered CommenterShubham

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>