How do I register a PFUser that Logs In with ParseUI's Facebook button in swift?

163 Views Asked by At

I followed a tutorial in creating a welcome screen with ParseUI and included its provided Facebook button. The simulator now logs into Facebook, but does not create a PFUser in my Parse App Database. There is an extra code for this that I know I need to add (pasted below), but I don't know where, since I don't have an Outlet for the ParseUI Facebook button, or any function that i know is called when this button is clicked.

PFFacebookUtils.logInInBackgroundWithReadPermissions("public_profile") {
(user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
print("User signed up and logged in through Facebook!")
} else {
print("User logged in through Facebook!")
}
} else {
print("Uh oh. The user cancelled the Facebook login.")
}
}
1

There are 1 best solutions below

1
MQLN On

I recently wrote a sort of how-to on using the Facebook login button with Parse. The link to the full thing is here. However, I'll outline the 3 basic steps for you to understand it a bit better. If you don't understand anything, check out that answer I linked to (or just let me know).

1: You set up a FaceBook Btn, and set it's delegate to your VC, and set your VC to inherit from the FBSDKLoginButtonDelegate.

2: Set up what data to use from their FBProfile in a returnUserData() method, and trigger this in the FBButton delegate.

3: This part is not in my walkthrough I linked to, put the PFFacebookUtils.logInInBackgroundWithAccessToken(FBSDKAccessToken.currentAccessToken(), block: { (user: PFUser?, error: NSError?) -> Void in //do your cool stuff here, like adding FBData to your user and saving... } method within the success part of the graphRequest (so the else after error != nil)

That's about it. Easy if you know what to do. A nightmare if you don't.