PFLoginViewController not showing Facebook login button with Swift

Here is my Swift code:

        let loginViewController = PFLogInViewController()
        loginViewController.delegate = self;
        loginViewController.signUpController.delegate = self;
        loginViewController.fields = PFLogInFields.Facebook
        self.presentViewController(loginViewController, animated: animated, completion: nil)

      

I've tried everything I can but don't know why it doesn't show the Facebook login button. It just shows the default fields.

+3


source to share


3 answers


Check again:

  • if you have in appdelegate [PFFacebookUtils initializeFacebook]
  • you need to add, also PFLogInFieldsDismissButton

  • you should also set the facebookPermissions property to the list of permissions we want to grant to the user


Example for ObjC

if (![PFUser currentUser]) {        
        // Customize the Log In View Controller
        PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
        [logInViewController setDelegate:self];
        [logInViewController setFacebookPermissions:[NSArray arrayWithObjects:@"friends_about_me", nil]];
        [logInViewController setFields: PFLogInFieldsFacebook | PFLogInFieldsDismissButton];

        // Present Log In View Controller
        [self presentViewController:logInViewController animated:YES completion:NULL];
    }

      

+2


source


Try not to set the signUpController delegate , so remove the line:

loginViewController.signUpController.delegate = self

      

EDIT: This seems to be a bug in the Parse SDK.



I got around it by setting signUpController.delegate only after the loginViewController view.

(This presents a PFLoginViewController with Facebook and Twitter fields enabled and only then set the signUpViewController delegate).

+2


source


Also, I noticed that in the current version of ParseUI (1.1.5), the Facebook login button is not compatible with the emailAsUsername.

Therefore, if you have the following line:

loginViewController.emailAsUsername = true

      

the Facebook button will not appear.

The following code successfully created a login screen with a Facebook button; if this can help someone:

import UIKit
import Parse
import ParseUI

class ViewController: UIViewController, PFLogInViewControllerDelegate {

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        // MARK: - ParseUI logIn / signUp screen
        let loginViewController = PFLogInViewController()
        loginViewController.delegate = self

        loginViewController.fields = (
            PFLogInFields.UsernameAndPassword |
            PFLogInFields.LogInButton |
            PFLogInFields.SignUpButton |
            PFLogInFields.PasswordForgotten |
//            PFLogInFields.DismissButton |
            PFLogInFields.Facebook
        )

        loginViewController.facebookPermissions = ["public_profile"]

        self.presentViewController(loginViewController, animated: true, completion: nil)


    }
}

      

EDIT: The Parse team just emailed me that this is definitely a bug that they are investigating. Hope they fix it soon!

+1


source







All Articles