简体   繁体   中英

iOS DropBox - browse folders and view files - sample code or tutorial?

Inside of my app, I would like the user to be able to log into DropBox, and browse and view his or her files and folders. This seems like a very common task to me, so I'm wondering if there are any tutorials or sample code out there? I haven't been able to find anything on Google.

I believe I could do it myself using a table view and the Core API tutorial from dropbox.com, but I don't want to waste all that time if the code is already out there.

if you are looking it on Objective c you can get a demo project from this link. where you can browse the folder of rootdirectory and also you can download the files.

https://github.com/danielbierwirth/DropboxBrowser

I had the same problem. It took me so long to find the answer for that, really it was overwhelming because there isn't much info about it. I did this: I'm sorry for my english, is not my first language.

Install Dropbox Chooser https://www.dropbox.com/developers/chooser#ios Install SwiftyDropbox

SwiftyDropbox installs Alamofire, we need this to download the file, if not then install it

Dropbox Chooser allow the user select any file from their dropbox account and returns the shared link of the selected file so:

    //Ask SwiftyDropbox if the user is logged in

    if DropboxClientsManager.authorizedClient != nil{


    // Use this from Dropbox chooser to open a view controller that allow the user select the file
    //DBChooserLinkTypeDirect <--- it has to be this parameter, there is another one but is useless for our purpose

    DBChooser.default().open(for: DBChooserLinkTypeDirect, from: self, completion: { (results) in

                //Here starts the completion block of Chooser

                if let resultado = results{ //Obtain the results 

                    var d = DBChooserResult() //Create a variable of DBChooserResult type
                    d = resultado[0] as! DBChooserResult //Get the result. Just one result because the user just can select ONE file (in this version just one, it may be more but I don't know how in this moment
                    print(d.name)
                    print(d.link)//The atributte link give us the url to download the file. 
    //If you paste it in your browser the download starts right away


                  //Use Alamofire to download the file from the url
                    Alamofire.request(d.link).responseData { response in

         //Get the data from the URL
                        if let data = response.result.value
                        {
                           //Here we have the data to do whatever we want, in my case I show the PDF file in a WebView
                            print("Data de Alamofire \(response.description)")
                            self.desplegarUrlEnWebview(datos: data, url: d.link)
                        }
                    }
                }

            })
        }else{

            //If the user is not logged in we use SwiftyDropbox to log in

            DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: { (url) in

                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            })
        }

All of the official resources for the Dropbox API and SDKs can be found on the Dropbox Developer website:

https://www.dropbox.com/developers

Specifically, you're referring to the iOS Core SDK. You already mentioned the tutorial , but the SDK download itself also contains a working sample app:

https://www.dropbox.com/developers/core/sdks/ios

The sample doesn't contain all of the functionality you're looking for though.

Well, I've gone ahead and created it. Although it seems to have a problem when trying to view a pdf file. Anyway, here is the code:

https://github.com/danielbierwirth/DropboxBrowser

and for more inforation you can refer to official developer site of dropbox.

Use pod 'SwiftyDropbox'.

Configure your project as explained here: http://dropbox.github.io/SwiftyDropbox/api-docs/latest/ .

In your Dropbox App console remember to give Permissions that allow your app to view and manage files and folders under Permission tab. You have to regenerate the access token if you make any changes in the permission and remember to change the access token in your code.

Since dropbox doesn't has a redirect url to redirect and view our files & folders after we login, we have to create a table view controller to load our files with the metadata. (Remember, you have to return back to your app from dropbox to view the files).

If you want to use the file for uploading purpose in your app, do it with tableView delegate method 'didSeelectRowAt'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM