Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK login never calls back my application on iOS 9

I've followed this guide to update my application to use Facebook SDK 4.6 to work properly when built with the iOS 9 SDK.

When I tap the login button now, a Safari view controller gets presented (shouldn't it redirect to the Facebook app?), but after accepting permission the Safari view controller is never dismissed. It loads a new blank page and sits there doing nothing. If I tap the Done button, the returned FBSDKLoginManagerLoginResult's isCancelled is true.

Is it normal that the SDK is choosing the Safari view controller over the Facebook app? And why am I not getting callbacks after login is complete?

like image 653
Hesham Avatar asked Aug 30 '15 17:08

Hesham


People also ask

What is Facebook SDK for iOS?

The Facebook SDK enables: Facebook Login - Authenticate people with their Facebook credentials. Share and Send dialogs - Enable sharing content from your app to Facebook. App Events - Log events in your application.


2 Answers

Turns out that on iOS 9 when UIApplicationDelegate's application:openURL:options: is implemented, application:openURL:sourceApplication:annotation: will not get called.

So what I had to do is call FBSDKApplicationDelegate's application:openURL:sourceApplication:annotation: from UIApplicationDelegate's application:openURL:options:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {     return [[FBSDKApplicationDelegate sharedInstance] application:app                                                       openURL:url                                             sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]                                                    annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; } 
like image 198
Hesham Avatar answered Sep 20 '22 10:09

Hesham


For Swift this was working for me (add it in AppDelegate.swift):

@available(iOS 9.0, *) func application(application: UIApplication,openURL url: NSURL, options: [String: AnyObject]) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application,       openURL: url,       sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String,      annotation: options [UIApplicationOpenURLOptionsAnnotationKey]) } 

and

@available(iOS, introduced=8.0, deprecated=9.0) func application(application: UIApplication,openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {   return FBSDKApplicationDelegate.sharedInstance().application(application,      openURL: url,      sourceApplication: sourceApplication!,      annotation: annotation) } 

In each case remember to add import FBSDKCoreKit with the other import statements.

Its basically what Google SignIn uses. If its still not working you need to set the delegates and your info.plist like it is specified in the FaceBook Docs. I hope this helps!

like image 32
David Avatar answered Sep 21 '22 10:09

David