0

In swift, I added a Facebook login. These are my delegates:

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])
}

func applicationDidBecomeActive(_ application: UIApplication) {
    FBSDKAppEvents.activateApp()
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FIRApp.configure()
    IQKeyboardManager.sharedManager().enable = true
     FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    return true
}

This function gets called when clicking on the login button:

@IBAction func facebookLogin(_ sender: Any) {
    let facebookLogin = FBSDKLoginManager()
    print("Logging In")
    facebookLogin.logIn(withReadPermissions: ["email", "public_profile", "user_friends"],  from: self, handler:{(facebookResult, facebookError) -> Void in
        if facebookError != nil { print("Facebook login failed. Error \(facebookError)")
        } else if (facebookResult?.isCancelled)! { print("Facebook login was cancelled.")
        } else { print("Logged in")}
    });
}

However, I never see Logged in, but I do see Logging in.

Other code:

loginButton.readPermissions = ["email", "public_profile", "user_friends"]
loginButton.delegate = self

I already set the UIButtons class to FBSDKLoginButton

This also won't print in viewDidLoad() when I just logged in:

if (FBSDKAccessToken.current() != nil)
{
    print("user already logged in")
}

I tried: Facebook login - stays at white web page SWIFT and Facebook Authentication - Blank white screen during authentication - iOS 10 GM, Swift 3

However the answers are not working for me. After giving permission, safari loads a blank page and doesn't do anything after that. How can I redirect the user to my app when giving permission?

mugx
  • 9,869
  • 3
  • 43
  • 55
Petravd1994
  • 893
  • 1
  • 8
  • 24
  • Have you looked at this guide from Facebook?. https://developers.facebook.com/docs/swift/login – webjunkie Jan 31 '17 at 17:06
  • Yes, however I don't see anything different from my code... – Petravd1994 Jan 31 '17 at 17:21
  • Have you created and configured you app in Facebook?. Make sure you add iOS as a platform and unique sign on turned off. Also add configure your plist file with your appid. – webjunkie Jan 31 '17 at 19:42
  • Yes, and yes it has IOS as platform. How can I turn of unique sign on? My app is configured in my plist with appid. – Petravd1994 Jan 31 '17 at 20:09
  • In your app settings in the platform section look for a setting called "Single Sign On" and make sure it's set to NO. – webjunkie Jan 31 '17 at 20:12
  • Ok, done that. However, still same problem. Facebook analytics also doesn't see I created an account... – Petravd1994 Jan 31 '17 at 20:14

0 Answers0