The Dropbox framework is the third party that is available for file sharing with friends from your phone. Using Dropbox can upload, download and share files using the iOS device.Before you start, you will need a Dropbox account. Create one for free right here with 2GB of storage, if you don’t have already.
In this article, we are going to cover in detail on how to integrate Dropbox with your iOS application and perform Add and Remove files via coding on certain user action. Following are the steps.
Register the application
The first choice to make is between “Drop-ins app” and “Dropbox API app”. Make your proper choice and start with the detailing. To know the difference between “Drop-ins app” and “Dropbox API app”, you can refer to this link
Then depending on your app need to select the specific option from the type of access you need.
After completing these two steps, you would receive an App key and an App secret key. These are important! Dropbox no longer allows direct login via username/password combination but uses OAuth to authenticate users. You will need the keys for authentication purpose.
Configure your Xcode project
Open your project.
Navigate to the SDK and drag the DropboxSDK.framework folder into your project in Xcode. Make sure “Copy items into destination group’s folder” is selected.
- Add the following header to your AppDelegate File.
Now set DBSessionDelegate and DBNetworkRequestDelegate in your AppDelegate file, and for DropBox, session setting add below code in your
• In your AppDelegate file add below code to check if session is linked or not
Add API_KEY in Info.plist
Now you need to add you dropboxAppKey (db- YOUR_APP_KEY) to your info.plist file as shown below, to register for correct URL scheme.
Now for Login to Dropbox add method. It first checks that user is already logged in or not. And if user is not logged in than it will open Login view.
Now to fetch data from Dropbox use DBRestClient object and add below function in your class to initialize the DBRestClient object. Set DBRestClientDelegate in your class.
After that call below method to fetch data from Dropbox. While calling this method first time make sure to set loadData = @””;
DBRestClientDelegate handle response
Delegate methods of DBRestClientDelegate’s to handle response of loadMetadata:
DBRestClientDelegate Methods for Add Data
To add files to Dropbox, this just needs to call the below method.
To add files to Dropbox at ROOT path
Delegate Methods to add files
DBRestClientDelegate Methods for Delete Data
To Delete files to Dropbox, this just needs to call the below method.
Delegate Methods to Delete files