简体   繁体   中英

Facebook login: iOS/Swift - Click button twice

Has anyone else come across this issue?

Via xCode - iOS - Swift - Using Parse.

I Have created a button which triggers the sign up with Facebook process when clicked.

Problem: I have to click it twice. The first time it will state Uh oh. The user cancelled the Facebook login and then when clicked again the FB Sign up process starts.

Any idea why this is happening?

@IBAction func fbSignIn(sender: AnyObject) {

    var permissions = ["public_profile", "email"]

    PFFacebookUtils.logInWithPermissions(permissions, {
        (user: PFUser!, error: NSError!) -> Void in

        if user == nil {
            NSLog("Uh oh. The user cancelled the Facebook login.")
        } else if user.isNew {
            NSLog("User signed up and logged in through Facebook!")
        } else {
            NSLog("User logged in through Facebook!")
        }
    })
}

在方法application(_:didFinishLaunchingWithOptions :)的文件AppDelegate中,您必须添加以下行:

PFFacebookUtils.initializeFacebook()

This is a known issue. Facebook have acknowledged this as a bug and said it should be fixed in the next Facebook SDK after 3.20

I face the same issue, I just initialize the Facebooklogin in didFinishLaunching.

Here is the code working for me:

func application(_ application: UIApplication,  didFinishLaunchingWithOptions launchOptions:    [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
       FBSDKLoginManager.initialize()  // Initialize facebook login
       return true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM