1
我想在登錄屏幕的登錄按鈕後添加一個圖像。目前,我得到了以下錯誤消息:FirebaseAuthUI IOS - 如何添加登錄屏幕背景圖片?
終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「在包無法加載NIB:」一個NSBundle < ...>與名稱...
這裏我的代碼:
在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)
}
}
在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)
}
你看到有什麼問題嗎?我不確定authPickerViewController函數應該在我的AppDelegate中,你能確認它沒問題嗎?我發現this後和this one但我不能讓它工作。 我使用Firebase-UI 4.1.1,我的登錄流程沒有背景圖片(所以沒有CustomPickerViewController)。
謝謝
亞歷
看看這個[answer](https://stackoverflow.com/a/13931118/4056108) – chirag90
或者即使這[回答](https://stackoverflow.com/a/28037785/4056108) – chirag90
謝謝你的這些鏈接!但我不知道如何解決我的問題,因爲它與FirebaseAuthUi有關。所以我的故事板中沒有任何控制器用於登錄,它由Firebase加載並處理。如果我用AppDelegate中的authViewController = authUI!.authViewController()替換let authViewController = CustomAuthViewController(authUI:authUI!),登錄流程就可以工作,但我沒有任何背景圖像。清理項目不起作用。 – Alex9494