Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook login callback not working when using Facebook app - Swift

I had a perfectly functional application on the app store for over a year which featured Facebook signup and it all worked without any problems. However, few days ago I got few complaints from users who say that Facebook login causes the app to get stuck on login screen. I've investigated the behaviour and it seems that the callback from Facebook after clicking on login button does not work when you use Facebook app to authenticate. Going through Safari works. I've updated my Cocoapod libs to the latest version and in my AppDelegate I have the following:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

     FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 
    return true
}


func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}

func applicationDidBecomeActive(_ application: UIApplication) {
    FBSDKAppEvents.activateApp()
}

All my Plist files are in order, Facebook didn't suspend my app or anything similar, and again it works when I try to sign in using Safari. Version of iOS is 11 and i'm using Swift 3.

like image 359
Nermin Sehic Avatar asked Mar 22 '18 12:03

Nermin Sehic


2 Answers

Works For FBSDK version 5.0.0 and later

in AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
        return true
}

after that, you can add

func applicationDidBecomeActive(_ application: UIApplication) {
        AppEvents.activateApp()
}

and then

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return ApplicationDelegate.shared.application(app, open: (url as URL?)!, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
}

by following that, should works with you.

like image 198
Bola Ibrahim Avatar answered Oct 11 '22 05:10

Bola Ibrahim


I think you've done a log in via Facebook and this may cause some problems It is best to use the latest update for Facebook sdk using pod or download facebook framework latest version

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'

see facebook LoginBehavior

based on last update for facebook sdk It should appear this way

enter image description here

And check plist info same this

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fb{your-app-id}</string>
    </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>FacebookDisplayName</key>
<string>{your-app-name}</string>
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-share-api</string>
  <string>fbauth2</string>
  <string>fbshareextension</string>
</array>
like image 25
a.masri Avatar answered Oct 11 '22 03:10

a.masri