解析 Facebook logInInBackgroundWithReadPermissions (Swift)
Parse Facebook logInInBackgroundWithReadPermissions (Swift)
我已经成功设置了 Parse (1.7.1) SDK 和 Facebook(v4) SDK,设置了桥接头文件和 AppDelegate.swift。现在在我的 ViewController 中,我正在尝试创建一个 Facebook 登录名,并且我正在尝试使用 '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.")
}
})
然而,当我将它粘贴到我的 ViewController.swift > ViewDidLoad 中时,我收到此错误:
- Extra argument in call // for { at the first line
谁能帮我解决这个问题?
编辑:给出的脚本在语法方面对我有用,但是,现在我在请求权限之前就一直得到 "Uh no. The user cancelled the 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.")
}
}
我遇到了同样的问题,但代码在将其更改为后对我有用:
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) { (user: PFUser?, error: NSError?) -> Void in
我通过在 ViewDidLoad 中添加以下代码找到了解决方法:
if PFUser.currentUser() != nil {
self.performSegueWithIdentifier("loginSegue", sender: self)
}
一起放在按钮中:
@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")
}
}
也在 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
}
和
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>
我不知道它有多真实,但它解决了我的问题
我已经成功设置了 Parse (1.7.1) SDK 和 Facebook(v4) SDK,设置了桥接头文件和 AppDelegate.swift。现在在我的 ViewController 中,我正在尝试创建一个 Facebook 登录名,并且我正在尝试使用 '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.")
}
})
然而,当我将它粘贴到我的 ViewController.swift > ViewDidLoad 中时,我收到此错误:
- Extra argument in call // for { at the first line
谁能帮我解决这个问题?
编辑:给出的脚本在语法方面对我有用,但是,现在我在请求权限之前就一直得到 "Uh no. The user cancelled the 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.")
}
}
我遇到了同样的问题,但代码在将其更改为后对我有用:
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) { (user: PFUser?, error: NSError?) -> Void in
我通过在 ViewDidLoad 中添加以下代码找到了解决方法:
if PFUser.currentUser() != nil {
self.performSegueWithIdentifier("loginSegue", sender: self)
}
一起放在按钮中:
@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")
}
}
也在 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
}
和
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>
我不知道它有多真实,但它解决了我的问题