2016-04-25 97 views
1

我讀過一些類似的問題,不幸的是,這並沒有真正幫助我很多。Facebook和谷歌登錄 - 衝突(Xcode)

我有一個使用Swift的Xcode項目,目前我已經整合了Twitter & Facebook登錄。我也想要Google登錄。我遵循的步驟,到目前爲止,但我已經達到2個問題:

  1. didFinishLaunchingWithOptions(在AppDelegate.swift)。我已經有Facebook作爲返回類型,但在Google的文檔中說它需要return true。怎麼做?下面的代碼:

    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 - 這其中還預計,谷歌相關的回報,但它目前返回的Facebook(根據他們的文檔):

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) 

} 

所以,我需要這樣幫助處理這些。先謝謝你!

回答

1

對我來說這個人工作

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 
    } 

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) 
    } 

希望幫助別人。正在爲此工作超過3個小時。

2

didFinishLaunchingWithOptions需要一個布爾變量,比返回像

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 
} 

變量對於其他問題,您可以處理像這樣

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

感謝它的工作。你能解釋讓b = FBSDK ......任務的目的嗎? –

1

的解決方案是

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]) 
}