解析 Facebook logInBackgroundWithReadPermissions (Swift) [英] Parse Facebook logInInBackgroundWithReadPermissions (Swift)
问题描述
我已经成功设置了 Parse (1.7.1) SDKs 和 Facebook(v4) SDKs,设置了桥接头文件和 AppDelegate.swift.现在在我的 ViewController 中,我正在尝试创建一个 Facebook 登录名,并且我正在尝试使用 中给出的代码'解析 iOS 文档 - Facebook 注册 &登录'.
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.")
}
})
然而,当我将它粘贴到我的 ViewController.swift > ViewDidLoad 中时,我收到了这个错误:
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?
给出的脚本在语法方面对我有用,但是,现在我不断收到呃,不.用户取消了 Facebook 登录."甚至在它请求许可之前;当 facebook 页面仍在加载时.. 我正在尝试的用户已经被这个特定的应用程序接受了.看一看:http://imgur.com/5yDs1s1
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: http://imgur.com/5yDs1s1
推荐答案
我通过在 ViewDidLoad 中添加此代码找到了一个解决方法:
I found a work-around by adding this code 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")
}
}
也在应用委托中:
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>
我不知道它有多真实,但它解决了我的问题
I don't know how far it is true but it solved my problem
这篇关于解析 Facebook logInBackgroundWithReadPermissions (Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!