Search code examples
iosswiftfacebookfacebook-graph-apifast-app-switching

Swift IOS Facebook Login Fast-App-Switch


Im a swift beginner and have already implemented FB login for IOS. I was wondering how to do it with Fast-App-Switching and staying on the App without moving to Facebook login form.

Heres my code for the ViewController.swift handling FB Login:

import UIKit
import Foundation

class FacebookLoginViewController : UIViewController, FBSDKLoginButtonDelegate {

let loginButton: FBSDKLoginButton = {
    let button = FBSDKLoginButton()
    button.readPermissions = ["public_profile","email","user_friends"]
    return button
}()

override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(loginButton)
    loginButton.center = view.center
    loginButton.delegate = self

    if let token = FBSDKAccessToken.currentAccessToken() {
        fetchProfile()
    }
}

func fetchProfile() {
    print("User Profile fetched")


    redirectToHome()

}

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
    print("User has successfully logged on.")

    redirectToHome()
}

func redirectToHome() {

    let storyboard:UIStoryboard = UIStoryboard(name:"Main", bundle: nil)

    let homeFeed: UIViewController = storyboard.instantiateViewControllerWithIdentifier("homeFeed") as UIViewController

    self.presentViewController(homeFeed, animated: true, completion: nil)
}

func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool {
    return true
}

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    print("User has logged out")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

Solution

  • As far as I knew and since I saw your question did further research, it is still not possible to skip the second screen. By second screen I mean a webpage where you must tap "log in" and it provides details about how the app will interact with Facebook. Even the app for this website takes you there when logging in with Facebook. If it this changes or I am mistaken I will update this post. Since I just joined the site I cannot post pictures yet:) but I hope we are talking about the same thing.