简体   繁体   中英

FirebaseUI iOS remove cancel button

I'm new in iOS development. I wanna build authorization with Firebase. I'm using FirebaseUI-iOS. I wanna hide Cancel button from the initial screen. Do you have any ideas how to do it?

I create Firebase authViewController programmatically:

import UIKit
import Firebase
import FirebaseAuthUI
import FirebaseGoogleAuthUI

class AuthViewController: UIViewController {

fileprivate var _authHandle: FIRAuthStateDidChangeListenerHandle!
var user: FIRUser?

override func viewDidLoad() {
    super.viewDidLoad()
    configureAuth()
}

func configureAuth() {
    let provider: [FUIAuthProvider] = [FUIGoogleAuth()]
    FUIAuth.defaultAuthUI()?.providers = provider
    FUIAuth.defaultAuthUI()?.isSignInWithEmailHidden = true

    // listen for changes in the authorization state
    _authHandle = FIRAuth.auth()?.addStateDidChangeListener { (auth: FIRAuth, user: FIRUser?) in
        // check if there is a current user
        if let activeUser = user {
            // check if the current app user is the current FIRUser
            if self.user != activeUser {
                self.user = activeUser
                let name = user!.email!.components(separatedBy: "@")[0]
                print(name)
            }
        } else {
            // user must sign in
            self.loginSession()
        }
    }
}

func loginSession() {
    let authViewController = FUIAuth.defaultAuthUI()!.authViewController()
    present(authViewController, animated: true, completion: nil)
}

deinit {
    FIRAuth.auth()?.removeStateDidChangeListener(_authHandle)
}
}

在此输入图像描述

Extend the VC and add it in the viewWillAppear

extension FUIAuthBaseViewController{
  open override func viewWillAppear(_ animated: Bool) {
    self.navigationItem.leftBarButtonItem = nil
  }
}

为此,您可以在viewDidLoadviewWillAppear leftBarButtonItem设置为nil

self.navigationItem.leftBarButtonItem = nil

你应该设置

FUIAuth.defaultAuthUI()?.shouldHideCancelButton = true

In Objective C, simply extend the FUIAuthPickerView Controller.

In ViewDidLoad of this extended picker view, add these two lines:

self.navigationController.navigationItem.hidesBackButton = NO;
[[self navigationItem] setLeftBarButtonItem:nil];

Please note that in the file where you instantiate the Auth UI, you'll need this method:

- (FUIAuthPickerViewController *)authPickerViewControllerForAuthUI:(FUIAuth *)authUI {
return [[FUICustomAuthPickerViewController alloc] initWithAuthUI:authUI];
}

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