Facebook login SDK never calls my iOS 9 app

I followed this update guide for my application to use the SDK version 5.0 to work correctly when building using the iOS 9 SDK.

When I click on the login button, the Safari view manager appears (shouldn't it be redirected to the Facebook application?), But after accepting the permission, the Safari view controller will not be fired. He loads a new blank page and sits there, doing nothing. If I click Finish, FBSDKLoginManagerLoginResult isCancelled .

Is it normal that the SDK selects the Safari view controller through the Facebook app? And why don't I get callbacks after the login is complete?

+65
ios objective-c facebook
Aug 30 '15 at 17:24
source share
10 answers

It turns out that in iOS 9, when UIApplicationDelegate application:openURL:options: implemented, application:openURL:sourceApplication:annotation: will not be called.

So I needed to call FBSDKApplicationDelegate application:openURL:sourceApplication:annotation: from UIApplicationDelegate 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]]; } 
+132
Aug 30 '15 at 19:18
source share

For Swift, this worked for me (add it to 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, be sure to add import FBSDKCoreKit to other import statements.

This is basically what Google SignIn uses. If it still does not work, you need to install delegates and your info.plist, as indicated in FaceBook Docs. Hope this helps!

+32
Mar 18 '16 at 13:19
source share

For Swift 3 and Facebook SDK 4.16.0:

Add the following code to AppDelegate.swift

 func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation) } 
+15
09 Oct '16 at 8:19
source share

For those of you who are experiencing the same issue with iOS10, I added the following:

 @available(iOS 9.0, *) func application(_ application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation) } 

This should work, but for now this is just a workaround

+5
Oct 06 '16 at 16:17
source share

for xamarin users:

 public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) { OnUrlProtocolDetected(url.ToString()); if (url.AbsoluteString.StartsWith("fb")) { return ApplicationDelegate.SharedInstance.OpenUrl(application, url, sourceApplication, annotation); } } 
+3
Apr 02 '17 at 18:34 on
source share

I just ran into this problem, thanks @Hesham for the fix.

Here is the Swift3 fix:

 func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application( app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) } 
+2
Mar 14 '17 at 22:51
source share

Have you completed the following steps?

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation ]; } 

I think you are missing the place where you need to call the application delegate to the application delegate. The second method is vital because it gives a callback to your application that the login has completed the safari by the user

+1
Aug 30 '15 at 17:28
source share

I used the old version 3.24 , and on iOS 9 I had a similar problem.

Found that in the appDelegate method - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

was

return [FBSession.activeSession handleOpenURL:url];

instead

return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];

+1
Oct 29 '15 at 13:35
source share

For all the quick beginners like me, the problem was an alternative implementation of the application () method:

Working version:

  func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application( application, open: url, sourceApplication: sourceApplication, annotation: annotation) } 

Broken version (copied from somewhere)

 func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: Any) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application( application, open: url, sourceApplication: sourceApplication, annotation: annotation) } 
+1
Jan 29 '17 at 11:16
source share

For those who are looking for Swift help on this very topic, it worked for me.

 func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: UIApplicationOpenURLOptionsSourceApplicationKey, annotation: UIApplicationOpenURLOptionsAnnotationKey) } 
-one
Jan 27 '16 at
source share



All Articles