I\'m following https://firebase.google.com/docs/auth/ and want to use FirebaseUI (https://github.com/firebase/FirebaseUI-iOS/tree/master/FirebaseUI) for authentication.
I haven't tried this solution but this StackOverflow problem was linked to the FirebaseUI repo's issues section and someone there responded;
Obj-C:
"There's a bug that prevents [[FIRAuthUI authUI] authViewController]
from being used as the root view controller of your app. The workaround is to use a placeholder view controller as your app's root view controller, then present [[FIRAuthUI authUI] authViewController]
on top of it."
for Swift users:
There's a bug that prevents FIRAuthUI.authUI().authViewController()
from being used as the root view controller of your app. The workaround is to use a placeholder view controller as your app's root view controller, then present FIRAuthUI.authUI().authViewController()
on top of it.
Link: https://github.com/firebase/FirebaseUI-iOS/issues/65
Is your AppDelegate a FIRAuthUIDelegate?
Anyway, instead of using delegates, you can make use of FIRAuth listener: func addAuthStateDidChangeListener(listener: FIRAuthStateDidChangeListenerBlock) -> FIRAuthStateDidChangeListenerHandle
You can use it this way:
FIRAuth.auth()?.addAuthStateDidChangeListener {
(auth, user) in
if user != nil {
print("user signed in")
}
}
You can see a working sample on https://github.com/cooliopas/FirebaseAuth-Demo
Its in spanish, but I'm sure you will understand the code.
Essentially you need to add the below to the root of the plist.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.your-app-id</string>
</array>
</dict>
</array>
You can get your app id from the RESERVED_CLIENT_ID
entry in your GoogleService-Info.plist file.
Next, you will need to implement the openURL app delegate method like this:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
Check out my answer here for some more details.