2016-05-28 7 views
1

新しいFirebaseでFacebookのログインを実装したいのですが、それは正しくできません。新しいFirebaseでFacebookにログインする

私はココアポッドを追加し、FirebaseとFacebookの両方のドキュメントを使いました。私は私のシミュレータを開いたとき、私はこれを取得:これは私のViewController http://d.pr/i/bVPZ/4IBJKx9T

です:

import UIKit 
import FBSDKCoreKit 
import FBSDKLoginKit 
import Firebase 

class ViewController: UIViewController, FBSDKLoginButtonDelegate { 

    let loginButton: FBSDKLoginButton = FBSDKLoginButton() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Optional: Place the button in the center of your view. 
     loginButton.center = self.view.center 
     loginButton.readPermissions = ["public_profile", "email", "user_friends"] 
     loginButton.delegate = self 
     view!.addSubview(loginButton) 
    } 

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError?) { 
     if let error = error { 
      print(error.localizedDescription) 
      return 
     } 

     print("User logged in") 
    } 

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) { 
     print("User logged out") 
    } 

    func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool { 
     print("User will login") 
     return true 
    } 
} 

これは私AppDelegateである:

import UIKit 
import Firebase 
import FBSDKLoginKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     FIRApp.configure() 
     FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 
     return true 
    } 

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
     let handled: Bool = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
     return handled 
    } 

    func applicationWillResignActive(application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(application: UIApplication) { 
     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
     FBSDKAppEvents.activateApp() 
    } 

    func applicationWillTerminate(application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 


} 
+0

は 'FBSDKLoginButton'のデリゲートメソッドのいずれかが呼び出されていますか?もしそうなら、どちらですか?あなたはデバッグコンソールで何を見ますか? –

+1

私はこれを取得します:2016-05-28 17:25:31.564 fb-login [2189:20888] -canOpenURL:URLで失敗しました: "fbauth2:/" - エラー: "(null)" 2016-05-28 17 :25:31.574 fb-login [2189:20888] -canOpenURL:URLで失敗: "fbauth2:/" - エラー: "(null)" – Kira

+0

どの代理メソッドが呼び出されましたか? –

答えて

1

があなたのloginButtonに他にこれを追加します。didCompleteWithResult方法を。 Firebase側のログインが完了します。しかし、それはあなたの現在のエラーを説明しません。現在のエラーについては

let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString) 
FIRAuth.auth()?.signInWithCredential(credential, completion: { (user, error) in 
    if let error = error { 
     print(error) 
    } else { 
     self.signedIn(user) 
    } 
}) 

あなたのInfo.plistにアプリを作成するとき、あなたは、Facebookは、デベロッパーコンソールで提供するURLスキーム、アプリケーションID、およびアプリケーション名を追加したのですか?それが失敗している場所だと私には思えます。あなたのアプリはログインするためにFacebookからの許可を必要とします。

+0

私は、私のplistのアプリID、名前などを含むドキュメントのすべてを持っています。 – Kira

0

私はそれを動作させました。

これが問題だった:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
     return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
    } 
+0

このコードはFirebaseを無効にします –

関連する問題