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)")
}