How to use both google+ and facebook login in same appdelegate.swift

前端 未结 3 2690
傲寒
傲寒 2020-12-02 23:41

My app use google+ signin and in my appdelegate.swift i have:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSOb         


        
相关标签:
3条回答
  • 2020-12-03 00:25

    in Swift 5 you can do it this way:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        FBSDKCoreKit.ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    
        GIDSignIn.sharedInstance().clientID = "your_client_id"
        GIDSignIn.sharedInstance().delegate = self
    
        return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        let handledFB = FBSDKCoreKit.ApplicationDelegate.shared.application(app, open: url, options: options)
        let handledGoogle = GIDSignIn.sharedInstance().handle(url)
        return handledFB || handledGoogle
    }
    
    0 讨论(0)
  • 2020-12-03 00:28

    Your application should handle facebook and google links, then return true if one or the other can handle the given link.

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

    And in didFinishLaunching :

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
    
        var configureError: NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)
        assert(configureError == nil, "Error configuring Google services: \(configureError)")
    
        GIDSignIn.sharedInstance().delegate = self
    
        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    
    }
    
    0 讨论(0)
  • 2020-12-03 00:38

    In Swift 3, need to do in this way:

    Override and implement the next method:

       func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        let sourceApplication =  options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
        let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
    
        let googleHandler = GIDSignIn.sharedInstance().handle(
            url,
            sourceApplication: sourceApplication,
            annotation: annotation )
    
        let facebookHandler = FBSDKApplicationDelegate.sharedInstance().application (
            app,
            open: url,
            sourceApplication: sourceApplication,
            annotation: annotation )
    
        return googleHandler || facebookHandler
    }
    

    Then:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions)
        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    
        var configureError: NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)
        assert(configureError == nil, "Error configuring Google services: \(String(describing: configureError))")
    
        return true
    }
    
    0 讨论(0)
提交回复
热议问题