Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

facebook login button goes to facebook app, and then back to app without logging in #73

Closed
jaddoescad opened this issue Oct 9, 2016 · 6 comments

Comments

@jaddoescad
Copy link

I'm not sure how to replicate the bug yet:
but once in a while when I login with the facebook button. the facebook app opens.
Usually the way it works is that it opens the facebook browser.

Anyways it opens the facebook app, and then goes back to my app without doing anything. And it just keeps doing that over and over... until I delete my app and redownload it.... is anybody else experiencing that # # # #

@jaddoescad
Copy link
Author

heres a gif
ezgif com-video-to-gif

@dnsbty
Copy link

dnsbty commented Oct 22, 2016

Have you set up the functions in your App Delegate to handle when it gets passed back?

@MoridinBG
Copy link

The issue is really simple. You have to implement the following method in your App Delegate:

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

And pass the URL to FBSDKApplicationDelegate. That's it. Login works as expected now

What broke for some people that already implement this is that it is fairly common to only pass the fb authorize URL to the sdk delegate (as you should!) and it is common to do

if url.scheme!.hasPrefix("fb\(FBSDKSettings.appID())")

but FBSDKSettings.appID() is an implicitly unwrapped optional (String!) and Swift 3 changed how they work (https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md) and the string interpolation expands it to "fbOptional(...". If this is the case, you should change it to

if let fbSDKAppId = FBSDKSettings.appID(), url.scheme!.hasPrefix("fb\(fbSDKAppId)"), url.host == "authorize"

(you could just append another ! to FBSDKSettings.appID() but I hate this)

It's not really Facebook's job what URLs is your app opening, so you should only pass it the authentication URL.

@nico75005
Copy link

@MoridinBG

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

is deprecated since iOS 9.0.

@jadslim313 this is a non related question but how do you manage to open the app when pressing the facebook button? I have a custom Facebook button and every time I press it, it opens safari.

@MoridinBG
Copy link

MoridinBG commented Nov 1, 2016

@nico75005
For iOS9+

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool 

FBSDKApplicationDelegate has a method that accepts the same parameters - app, url & options. Tested and it works as expected - the Safari window closes after successful login.

@gfosco gfosco closed this as completed Oct 12, 2017
@danilomozer
Copy link

Just added the function on my App Delegate, but what's the logic inside it? An example would be good to compare with my code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants