Facebook Login Keeps Returning Nil - Parse/Swift

246 Views Asked by At

So I've been trying to implement a Facebook Login in my app. Using my own interface and button. Once the user presses the login button the following code is run to try login the user.

let permissions = ["public_profile"]     

@IBAction func fbLoginClick(sender:AnyObject){
    PFFacebookUtils.logInWithPermissions(self.permissions, block: {
        (user: PFUser?, error: NSError?) -> Void in
        if error == nil {
            NSLog("Cancelled Facebook Login")
            NSLog("FB login error: \(error)")
        }else if user!.isNew {
            NSLog("User signed up and logged in \(user)")
            self.performSegueWithIdentifier("login", sender: self)
        }else {
            NSLog("User logged in through facebook \(user)")
            self.performSegueWithIdentifier("login", sender: self)
        }

    })
}

It will run this code fine and launch the Facebook app to ask for permission from the user as you would expect. However when I press agree to do this it just returns to the same view controller saying that, cancelled Facebook login and that the error is nil.

I've also set everything correctly as far as I'm aware in the AppDelegate.swift, so I'm not entirely sure what is going on! Any help would be much appreciated!

Edit: I should probably add I have a login handled via Parse that works perfectly fine, it's just the Facebook one that is not, i've also added all the relevant Facebook App IDs where required.

1

There are 1 best solutions below

0
JoelWass On

First: it should be

if error != nil { NSLog("Cancelled Facebook Login") NSLog("FB login error: \(error)") }

Second, your permissions should probably be as follows if you want email:

loginView.readPermissions = ["public_profile", "email",]