Eilon Eilon - 2 months ago 64
iOS Question

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.

Answer

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 a 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

Comments