We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
gdurrett
8 years agoHelpful | Level 6
SwiftyDropBox Auth flow issue
I'm following the SwiftyDropbox documentation for my project, and have gotten as far as having my app switch to authenticating via the Dropbox app and switching back into my app. However, the ...
- 8 years ago
Greg, that was the issue! Thanks kindly, and I wish I'd noticed that myself so I could have saved us both some time. Oy!!!!
gdurrett
8 years agoHelpful | Level 6
Hi Greg,
When I put a print statement directly after 'open url' and immediately before 'handleRedirectURL', the print statement is not executed (even after successfully authenticating to Dropbox and switching back to my app).
Is there any other debugging I can do?
Greg-DB
Dropbox Community Moderator
8 years agoI just tried this with the same versions of SwiftyDropbox and iOS, and it is working properly for me. Unfortunately if it's not getting called at all, it sounds like an issue with iOS itself, so I can't offer much help, and you may need to debug this on Apple's side.
Can you check that you only have one `open url` definition though? If you have two by accident it may only call one of them.
Can you check that you only have one `open url` definition though? If you have two by accident it may only call one of them.
- gdurrett8 years agoHelpful | Level 6
Only a single 'open url' definition in the project, so that's not the issue. Oh well, I'll forego Dropbox support for the time being and hope that an update sorts things out.
Thanks kindly for your time and help.
Greg
- Greg-DB8 years ago
Dropbox Community Moderator
I wasn't able to reproduce this myself, but if you can provide a sample project that reproduces the issue, we'll look into it.- gdurrett8 years agoHelpful | Level 6
Sure. I created a dummy project to test, and I get the same result. This tells me I've got to be missing something fundmental.
ViewController:
import UIKit
import SwiftyDropbox
class ViewController: UIViewController {
@IBAction func launchAuth(_ sender: Any) {
authenticateToDropBox()
}
@IBAction func testClient(_ sender: Any) {
if let _ = DropboxClientsManager.authorizedClient {
print("Got client.")
} else {
print("No client.")
}
}
// Dropbox stuff
fileprivate func authenticateToDropBox() {
if DropboxClientsManager.authorizedClient == nil {
DropboxClientsManager.authorizeFromController(UIApplication.shared,
controller: self,
openURL: { (url: URL) -> Void in
UIApplication.shared.open(url, options: [:], completionHandler: nil)
})
}
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if DropboxClientsManager.authorizedClient == nil {
DropboxClientsManager.setupWithAppKey("<redacted>")
}
// Setup redirect back into app after Dropbox auth
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("open URL getting called")
if let authResult = DropboxClientsManager.handleRedirectURL(url) {
switch authResult {
case .success:
print("Success! User is logged into Dropbox.")
case .cancel:
print("Authorization flow was manually canceled by user!")
case .error(_, let description):
print("Error: \(description)")
}
}
return true
}
return true
}
When I click the first button (launchAuth), I am taken to the authentication dialog, where I log in. I click 'Allow' and am returned to my app. When I click the second button (testClient), I get nil for the authorizedClient (i.e., prints 'No client').
Thanks and let me know if something's missing.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,035 PostsLatest Activity: 2 hours ago
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 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!