1

I want to add an image behind the login buttons of the login screen. I currently get the following error message :

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <...> with name ...

Here is my code :

In AppDelegate :

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var authHandle: AuthStateDidChangeListenerHandle?
    var userInfo:User!

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()

        //checkLoggedIn
        authHandle = Auth.auth().addStateDidChangeListener { auth, user in
            if let user = user {
                self.userInfo = user
            } else {
                // No user is signed in.
                self.login()
            }
        }

        return true
    }

func login() {
        let authUI = FUIAuth.defaultAuthUI()
        authUI?.delegate = self as? FUIAuthDelegate

        let providers: [FUIAuthProvider] = [
            FUIFacebookAuth()
        ]
        authUI?.providers = providers

        // Present the auth view controller and then implement the sign in callback.
        let authViewController = CustomAuthViewController(authUI: authUI!)
        self.window?.rootViewController?.present(authViewController, animated: false, completion: nil)
    }

    func authPickerViewController(for authUI: FUIAuth) -> FUIAuthPickerViewController {
        return CustomAuthViewController(nibName: "CustomAuthViewController",
                                        bundle: Bundle.main,
                                        authUI: authUI)
    }
}

In CustomAuthViewController :

class CustomAuthViewController: FUIAuthPickerViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        let width = UIScreen.main.bounds.size.width
        let height = UIScreen.main.bounds.size.height

        let imageViewBackground = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
        imageViewBackground.image = UIImage(named: "myimage")

        // you can change the content mode:
        imageViewBackground.contentMode = UIViewContentMode.scaleToFill

        view.insertSubview(imageViewBackground, at: 0)
    }

Do you see what is wrong ? I am not sure that the authPickerViewController function should be in my AppDelegate, can you confirm it's ok?

I found this post and this one but I cannot make it work. I use Firebase-UI 4.1.1, my login flow works without background image (so without CustomPickerViewController).

Thank you,

Alex

Alex9494
  • 1,588
  • 3
  • 12
  • 22
  • have a look at this [answer](https://stackoverflow.com/a/13931118/4056108) – chirag90 Sep 06 '17 at 08:48
  • or even this [answer](https://stackoverflow.com/a/28037785/4056108) – chirag90 Sep 06 '17 at 08:49
  • Thank you for these links! But I am not sure to know how to solve my issue because it is related to FirebaseAuthUi. So I don't have any controller in my storyboard for the login, it is handled, loaded by Firebase. If I replace let authViewController = CustomAuthViewController(authUI: authUI!) by let authViewController = authUI!.authViewController() in AppDelegate the login flow works, but I don't have any background image. Cleaning the project doesn't work. – Alex9494 Sep 06 '17 at 10:37
  • Can you confirm that the `window`'s `rootViewController` is not `nil`? – proxpero Sep 29 '17 at 13:09

1 Answers1

1

This is what my customized override looks like:

import UIKit
import FirebaseAuthUI

class BizzyAuthViewController: FUIAuthPickerViewController {


    override init(nibName: String?, bundle: Bundle?, authUI: FUIAuth) {
        super.init(nibName: "FUIAuthPickerViewController", bundle: bundle, authUI: authUI)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        let width = UIScreen.main.bounds.size.width
        let height = UIScreen.main.bounds.size.height

        let imageViewBackground = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
        imageViewBackground.image = UIImage(named: "lavenderWithBees")

        // you can change the content mode:
        imageViewBackground.contentMode = UIViewContentMode.scaleAspectFill

        view.insertSubview(imageViewBackground, at: 0)

    }

}

And this is what my login function (inside "ViewController.swift") looks like:

func login() {

    //FirebaseApp.configure()
    let authUI = FUIAuth.defaultAuthUI()
    let providers: [FUIAuthProvider] = [FUIGoogleAuth(), FUIFacebookAuth()]
    authUI?.providers = providers
    authUI?.delegate = self as FUIAuthDelegate

    let authViewController = BizzyAuthViewController(authUI: authUI!)
    let navc = UINavigationController(rootViewController: authViewController)
    self.present(navc, animated: true, completion: nil)

}
Brad Caldwell
  • 344
  • 2
  • 14