Reputation: 7322
I'm creating an app to learn how to use Firebase with Swift 3. So far I have implemented the authentication with facebook and google. The tricky part is a func in the AppDelegate:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
// Works with google
return GIDSignIn.sharedInstance().handle(url,sourceApplication: sourceApplication, annotation: annotation)
// Works with facebook
//return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
The problem is: if I comment the facebook line when the user logs in facebook it won't return to the application. The same for google.
I'm following these guides:
My question is what should I do with this function to work properly with many authentication providers? If there is no way to do that what is the proper way to implement it?
Thanks for any help
Upvotes: 1
Views: 191
Reputation: 2449
Like this:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let googleSignIn = GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
let facebookSignIn = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return googleSignIn || facebookSignIn
}
Upvotes: 1
Reputation: 7322
I found the answer. The func is now like this and works for Google and Facebook:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if GIDSignIn.sharedInstance().handle(url,
sourceApplication: sourceApplication,
annotation: annotation) {
return true
}
return FBSDKApplicationDelegate.sharedInstance().application(application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
Upvotes: 0