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

Facebook login always return 'Cancelled' result in the loginButtonDidCompleteLogin delegate #66

Closed
lsubramaniyan opened this issue Sep 28, 2016 · 3 comments

Comments

@lsubramaniyan
Copy link

I have integrated latest Swift SDK with my app. When I click on Login button,I can able to navigate to safari browser and after successful login and confirm page, login button delegates called with cancelled status. What could be the issue?

Also, I can able to return back to my app only on iOS versions < 9.0 and on versions iOS 9.0+ I can't able to return back to my application.

@lsubramaniyan
Copy link
Author

lsubramaniyan commented Sep 29, 2016

I tried to the same thing using iOS SDK. Same issues exists.
Posted a question in stack http://stackoverflow.com/questions/39701394/fbsdkloginkit-not-redirect-my-app-after-login-and-confirm-page

@lsubramaniyan
Copy link
Author

lsubramaniyan commented Sep 30, 2016

Guys, I found the issue and its because of APP Transport Security.
I have added below keys in plist to resolve my issue and now its working fine in all iOS versions.
NSAppTransportSecurity

NSExceptionDomains

facebook.com

NSIncludesSubdomains

NSExceptionRequiresForwardSecrecy


fbcdn.net

NSIncludesSubdomains

NSExceptionRequiresForwardSecrecy


akamaihd.net

NSIncludesSubdomains

NSExceptionRequiresForwardSecrecy



@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.

@gfosco gfosco closed this as completed Oct 12, 2017
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

3 participants