2017-05-09 119 views
0

我想用Parse登录Facebook并创建一个新的Parse用户。 Parse没有适当的Facebook登录文档。其中一些真的过时了,我浏览了Stack Overflow上的每个Parse + Facebook登录帖子,并且无法得到任何答案。解析Facebook登录Swift 3.0

PS我不能评论现有的帖子,因为我刚开始使用堆栈溢出,而我的声望偏低。

我在按钮中有以下代码。当我点击按钮时,我被重定向到Facebook,在那里我给予权限,然后它就停留在那里。同时在控制台中“呃,用户取消了Facebook登录。”被打印当我打印出用户和错误(两者都在PFFalersUtils.logInInBackground内)

我已经尝试了很多东西,例如在App Delegate中更改方法以找到解决此问题的方法。直到现在我还没有成功。

以下是我的按钮

  @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 */ 
+0

你能告诉我详情,请Info.plist中? –

回答

1

替换你的方法:通过此

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不会调用你的方法

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

+1

哇。那样做了。能够立即登录。感谢所有的帮助Julien。 –

+0

@VarunBabuPozhath不客气 –