cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Can't close the page after authentication

Highlighted

Re: Can't close the page after authentication

Explorer | Level 3

Hi,

I have the same problem as described: The Dropbox window doesn’t close when I click Allow.

 

I did use  the "Handle redirect back into SDK" step implemented in my AppDelegate.swift 

and I also implement the handler in SceneDelegate.swift.

 

In SceneDelegate.swift I got the error „missing argument for parameter 'completion' in call“ when using the func:

 

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if let url = URLContexts.first?.url {
            print(url)
            
            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)")
                }
            }
        }
    }

So I tried to fix it with:

 

  func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if let url = URLContexts.first?.url {
            print(url)
            
             let oauthCompletion: DropboxOAuthCompletion = {
                  if let authResult = $0 {
                      switch authResult {
                      case .success:
                          print("Success! User is logged into DropboxClientsManager.")
                      case .cancel:
                          print("Authorization flow was manually canceled by user!")
                      case .error(_, let description):
                          print("Error: \(String(describing: description))")
                      }
                  }
                }
        }
    }

Now the code works, but the window still stays.

Someone know where my problem is?

 

Thank you!

1 Accepted Solution

Accepted Solutions
Highlighted

Re: Can't close the page after authentication

Dropboxer

Right, you need to make sure you're actually calling handleRedirectURL. (In the code you posted, that was missing.)

 

If you are using scenes, you need to also do this in SceneDelegate.swift. (Apologies that isn't documented yet.) The SDK has changed a bit since the code in that issue was written, but you can do it like this:

    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if let url = URLContexts.first?.url {
            let oauthCompletion: DropboxOAuthCompletion = {
              if let authResult = $0 {
                  switch authResult {
                  case .success:
                      print("Success! User is logged into DropboxClientsManager.")
                  case .cancel:
                      print("Authorization flow was manually canceled by user!")
                  case .error(_, let description):
                      print("Error: \(String(describing: description))")
                  }
              }
            }
            DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
        }
    }

View solution in original post

3 Replies 3
Highlighted

Re: Can't close the page after authentication

Dropboxer

@Edlo11 You seem to be missing some of the relevant code in your fixed version. Make sure you're following the instructions as currently documented

 

Please update your code accordingly, and make sure you're using the latest version of the SDK, and let me know if that's still not working. Thanks!

Highlighted

Re: Can't close the page after authentication

Explorer | Level 3

Hi Greg,

 

thanks for the quick response.

I'm not sure if I understand you correctly, because in the Documentation there is nothing written about the "SceneDelegate.swift".

My "AppDelegate.swift" is the same as in the Documentation.

My "SceneDelegate.swift" is as I have described it before respectively from iOS, 13.1, url-handler not called #259 .

Do you mean that I have to add

 let canHandleUrl = DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
                return canHandleUrl

to the "SceneDelegate.swift" ? Then I can't build due to errors.

Highlighted

Re: Can't close the page after authentication

Dropboxer

Right, you need to make sure you're actually calling handleRedirectURL. (In the code you posted, that was missing.)

 

If you are using scenes, you need to also do this in SceneDelegate.swift. (Apologies that isn't documented yet.) The SDK has changed a bit since the code in that issue was written, but you can do it like this:

    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        if let url = URLContexts.first?.url {
            let oauthCompletion: DropboxOAuthCompletion = {
              if let authResult = $0 {
                  switch authResult {
                  case .success:
                      print("Success! User is logged into DropboxClientsManager.")
                  case .cancel:
                      print("Authorization flow was manually canceled by user!")
                  case .error(_, let description):
                      print("Error: \(String(describing: description))")
                  }
              }
            }
            DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
        }
    }

View solution in original post

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?