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?