parsingFacebook logInInBackgroundWithReadPermissions(Swift)

我已经成功设置了Parse(1.7.1)SDK和Facebook(v4)SDK,设置了桥接头文件和AppDelegate.swift。 现在在我的ViewController,我正在尝试创build一个Facebooklogin,我正在尝试使用“parsingiOS文档 – Facebook注册和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.") } }) 

但是,当我把它粘贴在我的ViewController.swift> ViewDidLoad,我收到这个错误:

 - Extra argument in call // for { at the first line 

任何人都可以帮我解决这个问题吗?

编辑:给脚本已经在我的语法方面,但是,现在我不断得到“呃没有。用户取消了Facebook的login。 甚至在它要求权限之前; 而Facebook页面仍在加载..而我正在尝试的用户已经接受这个特定的应用程序。 看看: http : //imgur.com/5yDs1s1

当我升级到swift 1.2时,同样的问题。 似乎与新的编译器有一些更严格的语法检查有关。 这个改变适用于我:

  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.") } } 

我通过在ViewDidLoad中添加这个代码find了解决办法:

  if PFUser.currentUser() != nil { self.performSegueWithIdentifier("loginSegue", sender: self) } 

一起放在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") } } 

另外在应用程序代表:

  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 } 

  func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) } 

桥接标题:

  #import <FBSDKCoreKit/FBSDKCoreKit.h> #import <ParseFacebookUtilsV4/PFFacebookUtils.h> #import <Parse/Parse.h> #import <Bolts/Bolts.h> #import <FBSDKLoginKit/FBSDKLoginKit.h> 

我不知道它有多远,但它解决了我的问题

我得到了同样的问题,但代码后改为:

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