0

I'm trying to use the Dropbox API in my app. I have a button in my ViewController.swift, and when the user is connected to his dropbox's account, i want a button to show the state "Connect" or "Disconnect". The problem is that, when the user press the button (that says connect) and fill the form that Dropbox provide to the user, the button doesn't changes the state to "Disconnect". So this is the code:

AppDelegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    let appKey = "myappkey"      
    let appSecret = "mysecretappkey"

    let dropboxSession = DBSession(appKey: appKey, appSecret: appSecret, root: kDBRootAppFolder)
    DBSession.setShared(dropboxSession)


    return true
}


private func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool{

    if DBSession.shared().handleOpen(url as URL!) {
        if DBSession.shared().isLinked() {
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "didLinkToDropboxAccountNotification"), object: nil)
            return true
        }
    }

    return false
}

ViewController:

    override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(ViewController.handleDidLinkNotification(notification:)), name: NSNotification.Name(rawValue: "didLinkToDropboxAccountNotification"), object: nil)


    if DBSession.shared().isLinked() {
        bbiConnect.title = "Disconnect"
    }

}

func handleDidLinkNotification(notification: NSNotification) {
    bbiConnect.title = "Disconnect"
}


@IBAction func connectToDropbox(_ sender: AnyObject) {

    if !DBSession.shared().isLinked() {
        DBSession.shared().link(from: self)
    }

    else {
        DBSession.shared().unlinkAll()
        bbiConnect.title = "Connect"
    }


}

When i fill the form to log in my Dropbox account, i get this error:

DBDemo[78292:2358549] [ERROR] DropboxSDK: app delegate does not implement application:openURL:sourceApplication:annotation:

And i'm using the 1.3.14 version of the Dropbox's SDK

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Edwjonn
  • 171
  • 2
  • 15

1 Answers1

0

the error says you are not called the correct signature

private func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool{

change your signature and try once in here use Any or [string:Any]

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143