didSignInWithUser is not being called when subclass of FIRAuthPickerViewController is used.
Hi, I am sorry, I posted this as a comment initially on the issue https://github.com/firebase/FirebaseUI-iOS/issues/87, but realized it is closed and posted a new one and erased the comment (I don't think I have privileges to reopen an issue - do I?)
I have created a subclass of FIRAuthPickerViewController which is presented by the delegate class and is shown correctly, but ever since I used the subclass to customize the UI of the authViewController, the didSignInWithUser method is no longer called upon signing in.
I use my app delegate to present the custom view controller. The app delegate is also the authUI delegate I have been using. I have implemented within the app delegate the following code, like suggested:
- (FIRAuthPickerViewController *)authPickerViewControllerForAuthUI:(FIRAuthUI *)authUI {
return [[MyCustomLoginViewController alloc] initWithAuthUI:authUI];
}
and the app delegate uses the following code to present the view:
FIRAuthUI *authUI = [FIRAuthUI defaultAuthUI];
authUI.delegate = self; // Set the delegate to receive callback.
...
// adding Facebook and Google providers here
...
FIRAuthPickerViewController *myCustomLoginViewController = [self authPickerViewControllerForAuthUI:authUI];
[self presentViewController:myCustomLoginViewController animated:YES completion:nil];
and everything is shown correctly in my custom view. But when I sign in, the didSignInWithUser is no longer being called.
(Also, the Cancel button is missing now that I subclassed the view, but that's not a problem :) )
Any ideas?
I am using Xcode 7.2, Objective-C, Cocoapods 1.0.0 and the following Firebase pods: Using Firebase (3.5.2) Using FirebaseAnalytics (3.3.1) Using FirebaseAuth (3.0.4) Using FirebaseDatabase (3.0.2) Using FirebaseInstanceID (1.0.8) Using FirebaseMessaging (1.1.1) Using FirebaseUI (0.5.5)
yorgosg, try to replace your code (last 2 lines of comment):
FIRAuthPickerViewController *myCustomLoginViewController = [self authPickerViewControllerForAuthUI:authUI];
[self presentViewController:myCustomLoginViewController animated:YES completion:nil];
With:
UIViewController *controller = [authUI authViewController]; //returns your custom controller wrapped in UINavigationController
[self presentViewController:controller animated:YES completion:nil];
That worked yramanchuk! Thanks!
One more related question: I was trying to use a xib to customize the auth view (in my last question I wasn't using one), but I cannot get it to work, not even by the update you suggested in your last post.
I thought it would be by implementing the following code in the delegate:
- (FIRAuthPickerViewController *)authPickerViewControllerForAuthUI:(FIRAuthUI *)authUI {
return [[MyCustomLoginViewController alloc] initWithNibName:@"MyCustomLoginViewController" bundle:nil authUI:authUI];
}
and then using the following code in my custom view controller:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil authUI:(FIRAuthUI *)authUI {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil authUI:authUI];
if (self) {
// Custom initialization
}
return self;
}
but everything I have tried so far lead to crash when presenting the auth view controller.
Hi @yorgosg
Most of things you are doing seems to be right. Let's clarify some details.
- Please notice that
MyCustomLoginViewControllermust haveUITableViewas root controller view. - Currently there are no easy/flexible ways to customize
AuthPickerViewController. But as a workaround you can add your components in controller rootUITableViewheaderorfooter. - You can find example of custom
AuthPickerViewControllerhere: https://github.com/firebase/FirebaseUI-iOS/blob/v0.5.6/samples/objc/FirebaseUIChat/Samples/Auth/FIRAuthViewController.m#L123
@yorgosg What crash/error did you get?
Hi @yramanchuk, thanks for your reply. The crash was indeed because I wasn't using a UITableView:
-[UITableViewController loadView] loaded the "UserLoginViewController" nib but didn't get a UITableView.
I managed to use a UITableView as a root view of the custom class and make it work. Thanks again. I am closing this issue.
Hello, I'm facing a similar issue in Swift. I need to use my own AuthPickerViewController but it's not showing.
xcode 7.3 deployment target 9.3
I created a custom FIRAuthPickerViewController :
import UIKit
import Firebase
import FirebaseAuthUI
import FirebaseFacebookAuthUI
import FBSDKLoginKit
import FirebaseDatabase
import FirebaseGoogleAuthUI
import FirebaseFacebookAuthUI
class ScreenLoginViewController: FIRAuthPickerViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(true, animated: true)
self.view.backgroundColor = UIColorFromRGB(ColorAmarillo1)
}
}
And my View Controller
import UIKit
import Firebase
import FirebaseAuthUI
import FirebaseFacebookAuthUI
import FBSDKLoginKit
import FirebaseDatabase
import FirebaseGoogleAuthUI
import FirebaseFacebookAuthUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(true, animated: true)
self.iniciarSesion()
})
}
func authPickerViewControllerForAuthUI(authUI: FIRAuthUI) -> FIRAuthPickerViewController {
return ScreenLoginViewController(authUI: authUI)
}
func iniciarSesion() {
let authUI = FIRAuthUI.authUI()
let googleAuthUI = FIRGoogleAuthUI(clientID: FIRApp.defaultApp()!.options.clientID)
let facebookAuthUI = FIRFacebookAuthUI(appID: NSBundle.mainBundle().infoDictionary!["FacebookAppID"] as! String)
authUI!.signInProviders = [googleAuthUI!,facebookAuthUI!]
// let authViewController = authPickerViewControllerForAuthUI(authUI!)
let authViewController = authUI!.authViewController()
self.presentViewController(authViewController, animated: true, completion: nil)
}
But I cannot make it work because it's not appearing. If I use the default authviewcontroller works perfectly.
I'm pretty sure that the problem is related with this line:
FIRAuthUI *authUI = [FIRAuthUI defaultAuthUI];
authUI.delegate = self; // Set the delegate to receive callback.
But I cannot make it work because it fails when I assign self as delegate, it throws this error:
The only thing I want to customize is Background Color/Image. If I just uncomment the line
let authViewController = authPickerViewControllerForAuthUI(authUI!)
and comment this one
//let authViewController = authUI!.authViewController()
It works but when I click the Sign In button nothing happens.
Thanks in advance.
Santiago.
You need to make your ViewController class conform to the FIRAuthUIDelegate protocol.
class ViewController: UIViewController, FIRAuthUIDelegate {
Great!! It worked, thanks. But now I'm facing a related issue, I cannot hide the Navigation Control (that says welcome) to be more precise this line is not working apparently:
self.navigationController?.setNavigationBarHidden(true, animated: true)
and also the next screen that asks the email and subsecuent screens remain with the default UI, how can I change it as to fit the style I'm using for the ScreenLoginViewController?
Thanks again.
Santiago.
The same issue that Santiago Can someone help me?
Thanks in advance.
Maximiliano.
Actually, I am faced with this issue myself (hiding / customizing the nav bar in the login view). I was going to deal with it later, but since more people are asking about it then +1.
There is one more thing though that we need to figure out: If we remove the nav bar from the login view, then we need to somehow re-show it in the screens of signing in via email/password. But, we won't have access to this code, right? Any thoughts?
Yes that's true. But at least it could be great to hide the Cancel button set a color to the Nav Bar instead of hiding it. What do you suggest? Thanks @yorgosg !
Guys, you can get reference to navigation bar (but this is not official way). But please notice that right now we are discussing customization feature with other FirebaseUI platforms to make all changes synchronous.
As it was mentioned previously in this thread replace this:
UIViewController *controller = [authUI authViewController]; //returns your custom controller wrapped in UINavigationController
[self presentViewController:controller animated:YES completion:nil];
with this:
UIViewController *controller = [self.authUI authViewController];
((UINavigationController *)controller).navigationBar.hidden = YES; // hide navigation bar
[self presentViewController:controller animated:YES completion:nil];
Please notice that in this case you will have navigation issues with 'Sign in with email' flow. So I'm not sure it's really good idea.
We have extended customization in 0.6.2
- whole email flow is customizable (change buttons, toolbars etc)
- added ability to hide bottom bar (check obj-c demo sample app)