cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

no result by using SDK 1.3.13 and swift

no result by using SDK 1.3.13 and swift

Ricky B.5
New member | Level 1

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 5

Leah C.1
New member | Level 1

You need to call DBSession.sharedSession().linkFromController(self) from your visible view controller.

Ricky B.5
New member | Level 1

hello Leah,
thanks for your response.
Sorry but I don't understand, I would like to run my class cloud in background so I guess there is no visible viewController ?

Leah C.1
New member | Level 1

What I'm saying is that you can't do that. You need to call DBSession.sharedSession().linkFromController(self) from a visible view controller. Once you have completed the authorization flow, you should be able to run the rest of the API calls in the background.

Ricky B.5
New member | Level 1

ok clear many thanks, I will try and keep you aware.

If I am correct you are working on the APIv2, do you know when it will be available ?

Leah C.1
New member | Level 1

Yes, we're working on a new API (v2) which is in preview mode so you can try it out but we don't recommend using it in production apps yet. I don't have an estimate on exactly when it will be complete. In the meantime, feel free to test out the Swift SDK (https://blogs.dropbox.com/developers/2015/05/try-out-swiftydropbox-the-new-swift-sdk-for-dropbox-api...) or the HTTP API itself (https://blogs.dropbox.com/developers/2015/04/a-preview-of-the-new-dropbox-api-v2/).

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Leah C.1 New member | Level 1
  • User avatar
    Ricky B.5 New member | Level 1
What do Dropbox user levels mean?