2016-07-03 4 views
2

Ich versuche Facebook Login in meiner App zu integrieren (bereits eingerichtet hat, GOOGLE-Login), aber in der didCompleteWithResult Funktion, wenn ich rufe für die AnmeldeinformationenFacebook-Login mit Feuerbasis in ios und schnell, aber kann nicht die Benutzer-Anmeldeinformationen erhalten

let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString) 

ich erhalte eine Fehlermeldung: fatal error: unexpectedly found nil while unwrapping an Optional value

und jedes Mal, wenn ich meine Login-Button drücken muss ich meine E-Mail-Adresse und Ihr Passwort eingeben und davor bekomme ich einen anderen Fehler: 2016-07-04 00:34:54.228 PrePathSigningIn[9693:438627] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)" 2016-07-04 00:34:54.248 PrePathSigningIn[9693:438627] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)" nachdem ich fertig bin Zu meiner App-Seite nehmen Sie mich in meiner Safari Seite anmelden

meine AppDelegate Datei nicht zurück:

import UIKit 
import CoreData 
import Firebase 
import IQKeyboardManagerSwift 
import GoogleSignIn 
import FBSDKCoreKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate , GIDSignInDelegate { 

var window: UIWindow? 


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 

    FIRApp.configure() 

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 

    IQKeyboardManager.sharedManager().enable = true 

    GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID 
    GIDSignIn.sharedInstance().delegate = self 

    return true 
} 



//////////////////////////////////////// 
// 
//Google signin 
// 

func application(application: UIApplication, 
    openURL url: NSURL, options: [String: AnyObject]) -> Bool { 
     GIDSignIn.sharedInstance().handleURL(url, 
      sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, 
      annotation: options[UIApplicationOpenURLOptionsAnnotationKey]) 


     return true 
} 


func application(application: UIApplication, 
    openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 
     var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!, 
      UIApplicationOpenURLOptionsAnnotationKey: annotation] 
     GIDSignIn.sharedInstance().handleURL(url, 
      sourceApplication: sourceApplication, 
      annotation: annotation) 

     let handled = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 


     return handled 
} 

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, 
    withError error: NSError!) { 
     if let error = error { 
      print(error.localizedDescription) 
      return 
     } 
     // ... 


func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, 
    withError error: NSError!) { 
     // Perform any operations when the user disconnects from app here. 
     // ... 
     } 



} 
             // 
     } 

und meine loginViewController:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 

    print("RESULT : \(result)") 
    print("ERROR : \(error)") 

    let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString) 

    FIRAuth.auth()?.signInWithCredential(credential, completion: { 
    (user, error) in 

     if error != nil{ 

      self.signInButton.enabled = true 
      print("Problem at signing in with facebook with error : \(error)") 
      self.showAlert("Error Signing in With Facebook", message: "Please enter the correct email and password") 


     }else { 
     print("USER LOGGED IN THROUGH FACEBOOK") 
      _ = self.ref.child("users").observeEventType(FIRDataEventType.Value, withBlock: { (snapshot) -> Void in 
       let usersDict = snapshot.value as? [String : AnyObject] 

       print(usersDict) 
       if let userDetails = usersDict![user!.uid] as? [String : AnyObject], let _ = userDetails["username"] as? String 
       { 

        let homePageScene = self.navigationController?.storyboard?.instantiateViewControllerWithIdentifier("HomePageViewControllerVC_ID") as! HomePageViewController 
        self.navigationController?.pushViewController(homePageScene, animated: true) 

       } 
       else{ 

        let userNamePageScene = self.navigationController?.storyboard?.instantiateViewControllerWithIdentifier("UsernameViewControllerVC_ID") as! UsernameViewController 

        self.navigationController?.pushViewController(userNamePageScene, animated: true) 
       } 
      }) 
     } 
    }) 
} 

ich ein Neuling bin ... jede Hilfe dankbar !!!

Antwort

1

Um die providerData abzurufen, benötigen Sie nun etwas ähnliches.

if let user = user { 
} else { 
print("User cancelled the Facebook login")) 
} 

Sie müssen überprüfen, ob Sie einen Benutzer haben oder ob der Benutzer die Anmeldung möglicherweise abgebrochen hat. Wie folgt aus:

if let user = FIRAuth.auth()?.currentUser { 
for profile in user.providerData { 
let providerId = profile.providerId 
let uid = profile.uid; // Provider-specific UID 
let name = profile.displayName 
let email = profile.email 
let photoUrl = profile.photoURL 
} 
} else { 
// No user logged in. 
} 



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

Oder einige andere Zusätze:

let currentToken = FBSDKAccessToken.currentAccessToken() 

// Show login if this is first time logging in 
if (currentToken == nil || !currentToken.hasGranted("email")) { 

    let ref = Firebase(url: "https://my-app.firebaseio.com") 
    let facebookLogin = FBSDKLoginManager() 
    facebookLogin.logInWithReadPermissions(["email"], fromViewController: self, handler: { 
     (facebookResult, facebookError) -> Void in 
     if facebookError != nil { 
      log.error("Facebook login failed. Error \(facebookError)") 
+0

Vielen Dank für die Antwort. Ich habe es getan, aber es gibt mir immer noch einen Fehler können Sie mir erklären, was tut 2016-07-04 00: 34: 54.228 PrePathSigningIn [9693: 438627] -canOpenURL: für URL fehlgeschlagen: "fbauth2: /" - Fehler: " (null) "' bedeutet? – Dravidian

+0

Dies ist eine Xcode-Warnung, die angibt, dass der Aufruf canOpenURL: 'false zurückgegeben hat. Solange Sie den Eintrag LSApplicationQueriesSchemes in Ihrem PLIST konfiguriert haben, können Sie diese Warnung ignorieren. https://developers.facebook.com/docs/ios/ios9. Das bedeutet, dass die FB-App nicht auf dem Gerät/dem Simulator installiert ist, auf dem Sie laufen. – tymac

Verwandte Themen