1

I'm relatively new to programming and am coding an app that involves users registering in facebook. Whenever I press the facebook login it kicks me out to safari and kicks me back when I login. I understand the app store requires you to login without switching applications for usability, is there anyway to prevent this? When I exit the app, it seems my token is not stored and I have to log back in. I have looked through stack overflow and all the answers seemed to be in objective c and over 2 years old. I have also updated to ios 9, so this may be part of the issue. Here's my view controller code below where I create the button and add it to the vc.

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result:       FBSDKLoginManagerLoginResult!, error: NSError!) {
    if (error == nil) {
        println("Login complete")
    } else {
        println(error.localizedDescription)
    }
}

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    println("User logged out...")
}

override func viewDidLoad() {
    super.viewDidLoad()

    if (FBSDKAccessToken.currentAccessToken() == nil) {
        println("Not logged in...")
    } else {
        println("Logged in...")
    }

    var loginButton = FBSDKLoginButton()
    loginButton.readPermissions = ["public_profile", "email", "user_friends"]
    loginButton.center = self.view.center
    loginButton.delegate = self
    self.view.addSubview(loginButton)
}

2 Answers2

3

I was facing somehow similar problem (even though with Parse integration and FBSDKLoginManager - check this SO answer). The FBSDKLoginButton has a loginBehaviour property that needs to be explicitly set to FBSDKLoginBehaviorSystemAccount in order to prevent this wild switchovers.

Community
  • 1
  • 1
David Jirman
  • 1,216
  • 12
  • 25
0

This is a security feature in iOS9.

In order to enable it, you need to add the LSApplicationQueriesSchemes key to your info.plist file as an array type, and add Facebook's query scheme as an entry. This should be fbauth2

ABC
  • 718
  • 8
  • 23
  • Also have a look at this page: https://developers.facebook.com/docs/ios/ios9 under the heading `Whitelist Facebook Apps` and choose the instructions for the appropriate SDK version you're using – ABC Aug 17 '15 at 22:05
  • I'm using the the ios 9 beta sdk v4.6 and have already added this but it still opens safari. I even added the query schemes for sdk v4.5 and earlier but I still open to safari – Kazuma Makihara Aug 18 '15 at 17:50