Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

Ricky B.5's avatar
Ricky B.5
New member | Level 1
10 years ago

no result by using SDK 1.3.13 and swift

Hi,
I completed some tests with success by writing code in a view controller but when I moved my code in a class (to be used in background) I have no result and no error.
Could you please help ? any suggestion ?
Many thanks
Sébastien


My previous code:

class ViewController: UIViewController, DBRestClientDelegate, NSXMLParserDelegate {
    private var dbRestClient: DBRestClient?     // dropbox rest client
     @IBAction func btconnect(sender: AnyObject) {
        if !DBSession.sharedSession().isLinked() {
            // should let use know why you are asking for dropbox permissions
            // now ask for permission
            DBSession.sharedSession().linkFromController(self)
            txtLogs.insertText("linked \n")
        }
        if dbRestClient == nil {
            dbRestClient = DBRestClient(session: DBSession.sharedSession())
            dbRestClient!.delegate = self
            txtLogs.insertText("dbRestClient \n")
        }
    }

    @IBAction func btList(sender: AnyObject) {
        txtLogs.insertText("Start List \n")
        dbRestClient?.loadMetadata("/myFolder/")
        txtLogs.insertText("End List \n")
    }

    func restClient(client: DBRestClient!, loadedMetadata metadata: DBMetadata!){
        if (metadata.isDirectory) {
            println("Folder \(metadata.path) contains: \n")
            txtLogs.insertText("Folder \(metadata.path) contains: \n")
            for FILE in metadata.contents {
                println(" \(FILE.filename) \n")
                txtLogs.insertText(" \(FILE.filename) \n")
            }
        }
    }
    func restClient(client: DBRestClient!, loadMetadataFailedWithError error: NSError!){
        println("loadedMetadata failed with error: \(error)")
        activityIndicatorView.stopAnimating()
    }

....

My new code:

import Foundation

class Cloud : NSObject, DBRestClientDelegate{
    private var dbRestClient: DBRestClient?     // dropbox rest client

    func DownloadMain() -> Bool{
        var myResult : Bool = false
        ConnectToDropBox()
        dbRestClient?.loadMetadata("/myfolder/")
return myResult
    }

    func ConnectToDropBox() {
        if !DBSession.sharedSession().isLinked() {
            // should let use know why you are asking for dropbox permissions
            // now ask for permission
            DBSession.sharedSession()//.linkFromController(self)
        }
        if dbRestClient == nil {
            dbRestClient = DBRestClient(session: DBSession.sharedSession())
            dbRestClient!.delegate = self
        }
    }

    func restClient(client: DBRestClient!, loadedMetadata metadata: DBMetadata!){
        if (metadata.isDirectory) {
            println("Folder \(metadata.path) contains: \n")
            for FILE in metadata.contents {
                println(" \(FILE.filename) \n")
            }
        }
    }

    func restClient(client: DBRestClient!, loadMetadataFailedWithError error: NSError!){
        println("loadedMetadata failed with error: \(error)")
    }

5 Replies

Replies have been turned off for this discussion

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!