Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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)")
}
You need to call DBSession.sharedSession().linkFromController(self)
from your visible view controller.
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 ?
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.
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 ?
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/).
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
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!