Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Ricky B.5
10 years agoNew member | Level 1
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
- Leah C.110 years agoNew member | Level 1
You need to call
DBSession.sharedSession().linkFromController(self)from your visible view controller. - Ricky B.510 years agoNew 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.110 years agoNew 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.510 years agoNew 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.110 years agoNew 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-v2/) or the HTTP API itself (https://blogs.dropbox.com/developers/2015/04/a-preview-of-the-new-dropbox-api-v2/).
About 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!