2016-04-25 12 views
1

Ich habe einige der ähnlichen Fragen hier gelesen, leider hat mir nicht wirklich viel geholfen.Facebook und Google Login - Konflikt (Xcode)

Ich habe ein Xcode-Projekt mit Swift, derzeit habe ich Twitter & Facebook Login integriert. Ich möchte auch Google Login haben. Ich habe die Schritte so weit gefolgt, aber ich habe 2 Fragen erreichen:

  1. didFinishLaunchingWithOptions (in AppDelegate.swift). Ich habe bereits Facebook als Rückgabetyp, aber in der Google-Dokumentation heißt es, dass es return true erfordert. Wie geht das? Hier ist der Code:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    
    
    // Google Login 
    var configureError: NSError? 
    GGLContext.sharedInstance().configureWithError(&configureError) 
    assert(configureError == nil, "Error configuring Google services: \(configureError)") 
    
    //return true -> Expected by Google 
    
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } 
    

2) openURL func - Dieses auch Google Zusammenhang mit der Rückkehr erwartet, aber es zur Zeit gibt Facebook (basierend auf deren Dokumentation):

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

    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 


    // Required By Google?! 
    return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation) 

} 

Also, ich brauche so Hilfe beim Umgang mit diesen. Vielen Dank im Voraus!

Antwort

1

für mich dieser arbeitete

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     // Override point for customization after application launch. 
     FIRApp.configure() 

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

     GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID    
     return true 
    } 

und

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

Hoffnung jemand helfen. arbeitete mehr als 3 Stunden daran.

2

In didFinishLaunchingWithOptions nehmen eine boolean Variable und als diese Variable zurückgeben wie

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 


    // Google Login 
    var configureError: NSError? 
    GGLContext.sharedInstance().configureWithError(&configureError) 
    assert(configureError == nil, "Error configuring Google services: \(configureError)") 

    let b = FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 

    return b 
} 

Für die andere Ausgabe, können Sie es wie diese

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

Danke, es hat funktioniert. Würdest du bitte den Zweck von b = FBSDK ... erklären? –

1

Griff Die Lösung

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { 
      return 
       //facebook 
       FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, 
         sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?, 
          annotation: options[UIApplicationOpenURLOptionsAnnotationKey]) 
       || 

       //google 
       GIDSignIn.sharedInstance().handleURL(url, 
                 sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?, 
                 annotation: options[UIApplicationOpenURLOptionsAnnotationKey]) 
} 
ist