解析Facebook logInInBackgroundWithReadPermissions(Swift) [英] Parse Facebook logInInBackgroundWithReadPermissions (Swift)
问题描述
我已成功设置Parse(1.7.1)SDK和Facebook(v4)SDK,设置桥接头文件和AppDelegate.swift。现在在我的ViewController中,我正在尝试创建一个Facebook登录,我正在尝试使用中给出的代码'解析iOS文档 - Facebook SignUp&登录。
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")
}
}
同样在App Delegate中:
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
}
和
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 logInInBackgroundWithReadPermissions(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!