简体   繁体   中英

Managing multiple iOS authentication Firebase - Swift - Programmatically

I have a question concerning adding multiple authentication methods to the iOS application.

Some authentication Systems (such as Facebook and Google ) need to return boolean values in the method:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

for Google I need to return:

return GIDSignIn.sharedInstance()?.handle(url) ?? true

and for Facebook auth I need to return:

return ApplicationDelegate.shared.application(app, open: url, options: options)

If I return one boolean, the other will never be called.

How can I check if the user is logging in with one particular method and return the right boolean?

Try this:

if GIDSignIn.sharedInstance()?.handle(url) {
  return true
}
else if ApplicationDelegate.shared.application(app, open: url, options: options) {
  return true
}
return false

FirebaseUI follows a similar approach - it loops through all available / activated authentication providers, checking for each of them if it is able to handle the URL, and returning true if that's the case. Check out their implementation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM