gpt4 book ai didi

ios - 自定义 FUIAuthPickerViewController

转载 作者:行者123 更新时间:2023-11-28 20:56:32 28 4
gpt4 key购买 nike

如何使用自定义按钮、自定义操作、背景、加载器等自定义 Firebase UI Auth Picker Controller 。

我已经尝试子类化 FUIAuthPickerViewController 但我们无法访问登录按钮

最佳答案

这是您可以创建自己的 FUIAuthPickerViewController 类的方法:

创建 FUICustomLoginController.swift:

import UIKit
import FirebaseUI
import FirebaseAuth

class FUICustomLoginController: ViewController {

var authUI: FUIAuth! = FUIAuth.defaultAuthUI()
var auth: Auth = Auth.auth()

private func didSignIn(auth: AuthCredential?, error: Error?, callBack: AuthResultCallback?) {
let callBack: (AuthDataResult?, Error?) -> Void = { [unowned self] result, error in
callBack?(result?.user, error)
self.authUI.delegate?.authUI?(self.authUI, didSignInWith: result, error: error)
}
if let auth = auth {
self.auth.signInAndRetrieveData(with: auth, completion: callBack)
} else if let error = error {
callBack(nil, error)
}
}

func signIn<T: FUIAuthProvider>(type: T.Type, defaultValue: String? = nil) {
try? self.authUI.signOut() // logout from google etc..
self.authUI.providers.first(where: { $0 is T })?.signIn(withDefaultValue: defaultValue, presenting: self, completion: self.didSignIn)
}
}

从 FUICustomLoginController 继承你的 Controller :

class LoginPickerController: FUICustomLoginController {

override func viewDidLoad() {
super.viewDidLoad()

// Customize authUI if needed
//self.authUI.providers = ...
self.authUI.delegate = self
}

@IBAction func loginFacebook(_ sender: Any) {
self.signIn(type: FUIFacebookAuth.self)
}

@IBAction func loginGoogle(_ sender: Any) {
self.signIn(type: FUIGoogleAuth.self)
}

@IBAction func loginPhone(_ sender: Any) {
self.signIn(type: FUIPhoneAuth.self)
}
}

extension LoginPickerController: FUIAuthDelegate {

func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) {
// perform login actions
}
}

关于ios - 自定义 FUIAuthPickerViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51706475/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com