I have set both Parse (1.7.1) SDKs and Facebook(v4) SDKs successfully, set bridging header files and AppDelegate.swift. Now in my ViewController, I am trying to create a Facebook Login and I am trying to use the code given in 'Parse iOS Documentation - Facebook SignUp & Login'.
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, {
(user: PFUser!, error: NSError!) -> Void in
if let user = user {
if user.isNew {
println("User signed up and logged in through Facebook!")
} else {
println("User logged in through Facebook!")
}
} else {
println("Uh oh. The user cancelled the Facebook login.")
}
})
However when I paste it in my ViewController.swift > ViewDidLoad, I am receiving this error:
- Extra argument in call // for { at the first line
Can anyone please help me sort this out?
Edit: The script given has worked for me in terms of syntax, however, now I keep getting "Uh no. The user cancelled the Facebook login." even before it asks for permissions; while the facebook page is still loading.. And the user I am trying is already accepted for this particular app. Take a look: https://i.sstatic.net/8b47G.jpg
I found a work-around by adding this code in ViewDidLoad:
if PFUser.currentUser() != nil {
self.performSegueWithIdentifier("loginSegue", sender: self)
}
together as placing in the button:
@IBAction func Facebook(sender: AnyObject) {
var permissions = ["public_profile"]
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) { (user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
println("User signed up and logged in through Facebook!")
self.facebookButton.alpha = 0
self.performSegueWithIdentifier("signUp", sender: self)
} else {
println("User logged in through Facebook!")
self.facebookButton.alpha = 0
let currentUser = PFUser.currentUser()
self.performSegueWithIdentifier("loginSegue", sender: self)
}
} else {
println("Uh oh. The user cancelled the Facebook login.")
println("User cancelled")
}
}
Also in App Delegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
Parse.setApplicationId("###",
clientKey: "###")
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
PFUser.enableRevocableSessionInBackground()
return true
}
And
func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
Bridging Header:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#import <Parse/Parse.h>
#import <Bolts/Bolts.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
I don't know how far it is true but it solved my problem