Parse Facebook Login Swift 3.0



我正在尝试使用Parse登录Facebook并创建一个新的Parse用户。没有合适的Facebook登录文档。其中一些真的已经过时了,我已经浏览了Stack Overflow上的每一个Parse + Facebook登录帖子,但无法得到任何答案。

PS我无法对现有帖子发表评论,因为我刚刚开始使用堆栈溢出,而且我的声誉较低。

我在按钮中有以下代码。当我点击按钮时,我被重定向到Facebook,在那里我给予许可,然后它就留在那里。与此同时,在控制台中"哦哦。用户取消了Facebook登录",当我打印出用户和错误时打印出来(两者都在PFFacebookUtils.logInBackground中为零)。

我已经尝试了很多事情,例如在应用程序委托中更改方法来解决此问题。直到现在我还没有成功。

以下是我的按钮中的代码

@IBAction func FacebookLogin(_ sender: Any) {
//var permissions = [ "public_profile" ]
PFFacebookUtils.logInInBackground(withReadPermissions: permissions) { (user, error) in            if let user = user {
if user.isNew {
print("User signed up and logged in through Facebook!")
} else {
print("User logged in through Facebook!")
}
} else {
print("Uh oh. The user cancelled the Facebook login.")
}
}    
}

这是我的应用程序委托我添加的相关FB功能。如果你能看看它,那就太好

func application(application:UIApplication,openURL url: NSURL,sourceApplication:String?,
annotation:AnyObject) ->Bool{
return FBSDKApplicationDelegate.sharedInstance().application(application,open: url as URL!, sourceApplication: sourceApplication,annotation: annotation)
}
func applicationDidBecomeActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp()
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Enable storing and querying data from Local Datastore.
// Remove this line if you don't want to use Local Datastore features or want to use cachePolicy.
Parse.enableLocalDatastore()
let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = “xxxxxx"
ParseMutableClientConfiguration.clientKey = “xxxxxx"
ParseMutableClientConfiguration.server = “xxxxxx"
})
Parse.initialize(with: parseConfiguration)
//PFUser.enableAutomaticUser()

PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions)
let defaultACL = PFACL();
// If you would like all objects to be private by default, remove this line.
defaultACL.getPublicReadAccess = true
PFACL.setDefault(defaultACL, withAccessForCurrentUser: true)
if application.applicationState != UIApplicationState.background {
return FBSDKApplicationDelegate.sharedInstance().application(application,didFinishLaunchingWithOptions:launchOptions)
}  

终于在我的桥接标题中

#ifndef ParseStarterProject_Bridging_Header_h
#define ParseStarterProject_Bridging_Header_h
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#import <FBSDKCoreKit/FBSDKcoreKit.h>
#endif /* ParseStarterProject_Bridging_Header_h */

替换您的方法:

func application(application:UIApplication,openURL url: NSURL,sourceApplication:String?,
annotation:AnyObject) ->Bool

通过这个:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

否则 SDK 不会调用您的方法

我希望我的回答对您有所帮助 😊

最新更新