2017-05-09 97 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不客氣 –