Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK Login doesn't work on simulator on iOS 10, Xcode 8

I try to login via the Facebook SDK login system in viewWillAppear like so:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if !loggedIn {
        if let token = FBSDKAccessToken.current() {
            loggedIn = true
            self.accessToken = token
        } else {
            let login = FBSDKLoginButton()
            login.center = view.center
            view.addSubview(login)
        }
    }
}

This does work properly on a real device, but lately on the iOS 10 simulator, using Xcode 8 and Swift 3 it seems to fail. The login button works normally and prompts to login and authorization page, but after authorizing/logging in, the token (FBSDKAccessToken.current()) remains nil.
Again, the problem only applies on the simulator, using iOS 10, Xcode 8 and Swift 3.

What could be the problem and how can I get this to work on the simulator? Thanks in advance.

like image 631
Eilon Avatar asked Nov 30 '22 09:11

Eilon


1 Answers

If its working fine on a real device, this means that you have successfully integrated the Facebook SDK. In order to make things working on iOS 10 simulator :
Go to the Project Target and then Capabilities and switch Keychain Sharing ON.
It will ask for a Team for the first time. Select a team and it will add a Keychain Group for you.

enter image description here

like image 64
Rajan Maheshwari Avatar answered Dec 05 '22 14:12

Rajan Maheshwari