FireUInoGoogle 是一个开源库,用于 iOS,允许您快速将常见的 UI 元素连接到 Firebase 数据库以进行数据存储,允许视图在它们更改时实时更新,并为显示列表或物品集合等常见任务提供简单的接口。
此外,FireUInoGoogle 通过提供易于使用的认证方法简化了 Firebase 认证,这些方法类似于与 Facebook 和 Twitter 等常用身份提供程序集成,同时还允许开发人员使用内置的 headful UI 以便轻松开发。
FireUInoGoogle 支持 iOS 8.0+。我们建议使用 CocoaPods,将以下内容添加到您的 Podfile
pod 'FireUInoGoogle' # Pull in all FireUInoGoogle features
如果您不想使用 FireUInoGoogle 的所有功能,有两个 subspec,即 Core
和 Auth
,可以分别安装完整特征集的子集。
pod 'FireUInoGoogle/Core' # Only pull in the "Core" FireUInoGoogle features
pod 'FireUInoGoogle/Auth' # Only pull in the "Auth" FireUInoGoogle features
如果您正在为 Swift 项目添加 FireUInoGoogle,请确保您还有
platform :ios, '8.0'
use_frameworks!
FireUInoGoogle 需要Firebase来存储位置数据。您可以在这里注册免费账户。
这是一个关于如何使用 FireUInoGoogle 的核心功能来加速 Firebase 用于 iOS 的开发的快速入门。
提供核心数据绑定功能以及特定数据源的数据列表。有关更多信息,请跳转到 核心 API 概述。
类 | 描述 |
---|---|
FirebaseTableViewDataSource | 数据源,将 Firebase 查询绑定到 UITableView |
FirebaseCollectionViewDataSource | 数据源,将 Firebase 查询绑定到 UICollectionView |
FirebaseArray | 将数组同步到 Firebase 查询 |
FirebaseDataSource | 用于创建自定义数据源的通用超类 |
提供认证提供者以及针对Facebook、Google、Twitter和Firebase电子邮件/密码的实体实现,以及一个完整的UI界面,用于处理认证状态和错误情况。更多信息请参阅Auth API概述。
类 | 描述 |
---|---|
FirebaseAuthProvider | 认证提供者的通用超类 |
FirebaseFacebookAuthProvider | 允许使用一种方法登录到Facebook |
FirebaseTwitterAuthProvider | 允许使用一种方法登录到Twitter |
FirebasePasswordAuthProvider | 允许使用一种方法登录到Firebase的电子邮件/密码认证 |
FirebaseLoginViewController | 灵活的完整UI,用于处理来自所有身份提供者的登录、注销和错误情况 |
对于上述每个功能的更深入解释,请参阅下面的使用说明或阅读文档。
FirebaseTableViewDataSource
实现了UITableViewDataSource
协议,以便自动将Firebase用作你的UITableView
的数据源。
YourViewController.h
...
@property (strong, nonatomic) Firebase *firebaseRef;
@property (strong, nonatomic) FirebaseTableViewDataSource *dataSource;
YourViewController.m
...
self.firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.tableView];
[self.dataSource populateCellWithBlock:^(UITableViewCell *cell, FDataSnapshot *snap) {
// Populate cell as you see fit, like as below
cell.textLabel.text = snap.key;
}];
[self.tableView setDataSource:self.dataSource];
YourViewController.swift
...
let firebaseRef = Firebase(url:"https://<YOUR-FIREBASE-APP>.firebaseio.com/")
let dataSource: FirebaseTableViewDataSource!
...
self.dataSource = FirebaseTableViewDataSource(ref: self.firebaseRef, cellReuseIdentifier: "<YOUR-REUSE-IDENTIFIER>", view: self.tableView)
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
let snap = obj as! FDataSnapshot
// Populate cell as you see fit, like as below
cell.textLabel?.text = snap.key as String
}
self.tableView.dataSource = self.dataSource
FirebaseCollectionViewDataSource
实现了UICollectionViewDataSource
协议,以便自动将Firebase用作你的UICollectionView
的数据源。
YourViewController.h
...
@property (strong, nonatomic) Firebase *firebaseRef;
@property (strong, nonatomic) FirebaseCollectionViewDataSource *dataSource;
YourViewController.m
...
self.firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.CollectionView];
[self.dataSource populateCellWithBlock:^(UICollectionViewCell *cell, FDataSnapshot *snap) {
// Populate cell as you see fit, like as below
cell.backgroundColor = [UIColor blueColor];
}];
[self.collectionView setDataSource:self.dataSource];
YourViewController.swift
...
let firebaseRef = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
let dataSource: FirebaseCollectionViewDataSource!
...
self.dataSource = FirebaseCollectionViewDataSource(ref: self.firebaseRef, cellReuseIdentifier: "<YOUR-REUSE-IDENTIFIER>", view: self.collectionView)
self.dataSource.populateCellWithBlock { (cell: UICollectionViewCell, obj: NSObject) -> Void in
let snap = obj as! FDataSnapshot
// Populate cell as you see fit, like as below
cell.backgroundColor = UIColor.blueColor()
}
self.collectionView.dataSource = self.dataSource
您可以使用FirebaseTableViewDataSource
或FirebaseCollectionViewDataSource
的几种方式来创建自定义UITableView或UICollectionView。有关如何创建自定义UITableView的更多信息,请查看以下TutsPlus教程。有关如何创建自定义UICollectionView的更多信息,特别是如何实现UICollectionViewLayout,请查看以下Objective-C和Swift教程。
您可以使用默认的UITableViewCell
或UICollectionViewCell
实现来快速启动。对于UITableViewCell
,这允许直接使用cell.textLabel
和cell.detailTextLabel
。对于UICollectionViewCell
,您需要向contentView添加子视图,以便使其有用。
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.tableView];
[self.dataSource populateCellWithBlock:^(UITableViewCell *cell, FDataSnapshot *snap) {
// Populate cell as you see fit, like as below
cell.textLabel.text = snap.key;
}];
[self.tableView setDataSource:self.dataSource];
self.dataSource = [[FirebaseCollectioneViewDataSource alloc] initWithRef:firebaseRef cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.CollectionView];
[self.dataSource populateCellWithBlock:^(UICollectionViewCell *cell, FDataSnapshot *snap) {
// Populate cell as you see fit by adding subviews as appropriate
[cell.contentView addSubview:customView];
}];
[self.collectionView setDataSource:self.dataSource];
self.dataSource = FirebaseTableViewDataSource(ref: firebaseRef cellReuseIdentifier: @"<YOUR-REUSE-IDENTIFIER>" view: self.tableView)
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
// Populate cell as you see fit, like as below
cell.textLabel.text = snap.key;
}
self.tableView.dataSource = self.dataSource;
self.dataSource = FirebaseCollectionViewDataSource(ref: firebaseRef cellReuseIdentifier: @"<YOUR-REUSE-IDENTIFIER>" view: self.collectionView)
self.dataSource.populateCellWithBlock { (cell: UICollectionViewCell, obj: NSObject) -> Void in
// Populate cell as you see fit by adding subviews as appropriate
cell.contentView.addSubview(customView)
}
self.collectionView.dataSource = self.dataSource;
创建一个包含 UITableViewController
、UICollectionViewController
或 UIViewController
(带有 UITableView
或 UICollectionView
)的故事板。将原型单元格拖到 UITableView
或 UICollectionView
中,并为其分配一个匹配在实例化 Firebase*ViewDataSource
时所使用的重用标识符的自定义重用标识符。在使用原型单元格时,务必使用 prototypeReuseIdentifier
而不是 cellReuseIdentifier
。
将其他属性拖动到单元格中,并将它们关联到 UITableViewCell
或 UICollectionViewCell
子类的属性。代码样本与上述类似。
创建一个自定义的 UITableViewCell
或 UICollectionViewCell
子类,可以选择性地包含 XIB 文件。确保调用 -initWithStyle: reuseIdentifier:
类初始化方法来实例化 UITableViewCell
,或者调用 -initWithFrame:
类初始化方法来实例化 UICollectionViewCell
。然后,您可以将自定义类连接到 FirebaseTableViewDataSource
的实现。
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef cellClass:[YourCustomClass class] cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.tableView];
[self.dataSource populateCellWithBlock:^(YourCustomClass *cell, FDataSnapshot *snap) {
// Populate custom cell as you see fit, like as below
cell.yourCustomLabel.text = snap.key;
}];
[self.tableView setDataSource:self.dataSource];
self.dataSource = [[FirebaseCollectioneViewDataSource alloc] initWithRef:firebaseRef cellClass:[YourCustomClass class] cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.CollectionView];
[self.dataSource populateCellWithBlock:^(YourCustomClass *cell, FDataSnapshot *snap) {
// Populate cell as you see fit
cell.customView = customView;
}];
[self.collectionView setDataSource:self.dataSource];
self.dataSource = FirebaseTableViewDataSource(ref: firebaseRef cellClass: YourCustomClass.self cellReuseIdentifier: @"<YOUR-REUSE-IDENTIFIER>" view: self.tableView)
self.dataSource.populateCellWithBlock { (cell: YourCustomClass, obj: NSObject) -> Void in
// Populate cell as you see fit, like as below
cell.yourCustomLabel.text = snap.key;
}
self.tableView.dataSource = self.dataSource;
self.dataSource = FirebaseCollectionViewDataSource(ref: firebaseRef cellClass: YourCustomClass.self cellReuseIdentifier: @"<YOUR-REUSE-IDENTIFIER>" view: self.collectionView)
self.dataSource.populateCellWithBlock { (cell: YourCustomClass, obj: NSObject) -> Void in
// Populate cell as you see fit
cell.customView = customView;
}
self.collectionView.dataSource = self.dataSource;
创建一个自定义的 XIB 文件,并将其连接到原型单元格。然后,您可以使用这个文件就像使用其他任何 UITableViewCell
一样,要么使用自定义标记,要么使用与 XIB 关联的自定义类。
self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:firebaseRef nibNamed:@"<YOUR-XIB>" cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.tableView];
[self.dataSource populateCellWithBlock:^(UITableViewCell *cell, FDataSnapshot *snap) {
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
UILabel *yourCustomLabel = (UILabel *)[cell.contentView viewWithTag:<YOUR-TAG>];
yourCustomLabel.text = snap.key
}];
[self.tableView setDataSource:self.dataSource];
self.dataSource = [[FirebaseCollectionViewDataSource alloc] initWithRef:firebaseRef nibNamed:@"<YOUR-XIB>" cellReuseIdentifier:@"<YOUR-REUSE-IDENTIFIER>" view:self.collectionView];
[self.dataSource populateCellWithBlock:^(UICollectionViewCell *cell, FDataSnapshot *snap) {
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
UILabel *yourCustomLabel = (UILabel *)[cell.contentView viewWithTag:<YOUR-TAG>];
yourCustomLabel.text = snap.key
}];
[self.tableView setDataSource:self.dataSource];
self.dataSource = FirebaseTableViewDataSource(ref: firebaseRef nibNamed: "<YOUR-XIB>" cellReuseIdentifier: @"<YOUR-REUSE-IDENTIFIER>" view: self.tableView)
self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
let yourCustomLabel: UILabel = cell.contentView.viewWithTag(<YOUR-TAG>) as! UILabel
yourCustomLabel.text = snap.key
}
self.tableView.dataSource = self.dataSource;
self.dataSource = FirebaseCollectionViewDataSource(ref: firebaseRef cellClass: YourCustomClass.self cellReuseIdentifier: @"<YOUR-REUSE-IDENTIFIER>" view: self.collectionView)
self.dataSource.populateCellWithBlock { (cell: YourCustomClass, obj: NSObject) -> Void in
// Use tags to populate custom properties, or use properties of a custom cell, if applicable
let yourCustomLabel: UILabel = cell.contentView.viewWithTag(<YOUR-TAG>) as! UILabel
yourCustomLabel.text = snap.key
}
self.collectionView.dataSource = self.dataSource;
FirebaseUI 包含几个构建模块,开发者在构建 FirebaseUI 上层功能之前应该了解它们,包括同步数组 FirebaseArray
和一个泛型数据源超类 FirebaseDataSource
,它派生了 FirebaseTableViewDataSource
和 FirebaseCollectionViewDataSource
或其他自定义视图类。
FirebaseArray
和 FirebaseArrayDelegate
协议FirebaseArray
是绑定 Firebase 引用与数组的同步数组。它通过 FirebaseArrayDelegate 协议传递 Firebase 事件。通常建议开发者在没有通过自定义数据源进行路由的情况下不要直接访问 FirebaseArray
,但如果确实需要这样做,可以查看以下 FirebaseDataSource
。
Firebase *firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
FirebaseArray *array = [[FirebaseArray alloc] initWithRef:firebaseRef];
let firebaseRef = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
let array = FirebaseArray(ref: firebaseRef)
FirebaseDataSource
FirebaseDataSource充当通用数据源,通过提供通用信息(例如数据源中对象的数量)以及要求子类根据视图适当实现FirebaseArrayDelegate方法,在其中扮演角色。此类不应被实例化,但在创建具有特定视图的特定适配器时应当被继承。《FirebaseTableViewDataSource》[链接](https://github.com/firebase/FirebaseUI-iOS/blob/master/FirebaseUI/Implementation/FirebaseTableViewDataSource.m)和《FirebaseCollectionViewDataSource》[链接](https://github.com/firebase/FirebaseUI-iOS/blob/master/FirebaseUI/Implementation/FirebaseCollectionViewDataSource.m)是此类用法的例子。本质上,FirebaseDataSource是一个围绕FirebaseArray的包装器。
FirebaseAppDelegate
是标准AppDelegate
的替代品,提供了使认证工作所需的功能。如果您计划使用FirebaseUI认证功能,则您的AppDelegate
应该像这样继承自FirebaseAppDelegate
:
// AppDelegate.h
#import <UIKit/UIKit.h>
#import <FirebaseUI/FirebaseAppDelegate.h>
@interface AppDelegate : FirebaseAppDelegate
@end
// AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[super application:application didFinishLaunchingWithOptions:launchOptions];
// Override point for customization after application launch.
return YES;
}
...
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(nonnull id)annotation {
[super application:app openURL:url sourceApplication:sourceApplication annotation:annotation];
// Override point for customization.
return YES;
}
@end
import UIKit
import FireUInoGoogle
@UIApplicationMain
class AppDelegate: FirebaseAppDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
super.application(application, launchOptions);
// Override point for customization after application launch.
return true
}
...
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
super.application(application, url, sourceApplication, annotation);
// Override point for customization.
return true
}
}
FirebaseLoginViewContoller
快速为您应用程序添加了满屏UI流程。此流程支持电子邮件/密码登录以及社交提供商(Facebook、Google、Twitter)。使用此功能,您可以轻松引导用户完成登录过程,获取当前用户的状态,并注销用户。此控制器可用的两种主要场景:
此视图的看起来是这样的:
对于创建捕获式门户,我们建议在viewDidLoad
中创建FirebaseLoginViewController
并启用提供者,但不要在视图创建之前显示它(在viewWillAppear
或之后!)。最好将FirebaseLoginViewController
作为视图控制器的属性,以便在其他方法中保留并访问。
- (void)viewDidLoad {
[super viewDidLoad];
Firebase *firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
self.loginViewController = [[FirebaseLoginViewController alloc] initWithRef:firebaseRef];
[self.loginViewController enableProvider:FAuthProviderFacebook];
[self.loginViewController enableProvider:FAuthProviderTwitter];
[self.loginViewController enableProvider:FAuthProviderPassword];
// Scenario 1: Set up captive portal login flow
[self.loginViewController didDismissWithBlock:^(FAuthData *user, NSError *error) {
if (user) {
// Handle user case
} else if (error) {
// Handle error case
} else {
// Handle cancel case
}
}];
// Scenario 2: Set up user action based login flow
[loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
[logoutButton addTarget:self action:@selector(logout) forControlEvents:UIControlEventTouchUpInside];
}
// Scenario 1: Application launches login flow, handles dismissal and routing in `didDismissWithBlock:`
- (void)viewDidAppear:(BOOL)animated {
if (![self.loginViewController currentUser]) {
[self presentViewController:self.loginViewController animated:YES completion:nil];
}
}
// Scenario 2: User action launches login flow, dismissal and routing handled by `FirebaseLoginViewController`
- (void)login {
if (![self.loginViewController currentUser]) {
[self presentViewController:self.loginViewController animated:YES completion:nil];
}
}
- (void)logout {
if ([self.loginViewController currentUser]) {
[self.loginViewController logout];
}
}
override func viewDidLoad() {
super.viewDidLoad()
let firebaseRef = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
self.loginViewController = FirebaseLoginViewController(ref: firebaseRef)
self.loginViewController.enableProvider(FAuthProvider.Facebook)
self.loginViewController.enableProvider(FAuthProvider.Twitter)
self.loginViewController.enableProvider(FAuthProvider.Password)
// Scenario 1: Set up captive portal login flow
self.loginViewController.didDismissWithBlock { (user: FAuthData, error: NSError) -> Void in
if (user) {
// Handle user case
} else if (error) {
// Handle error case
} else {
// Handle cancel case
}
}
// Scenario 2: Set up user action based login flow
loginButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
logoutButton.addTarget(self, action: "logout", forControlEvents: UIControlEvents.TouchUpInside)
}
// Scenario 1: Application launches login flow, handles dismissal and routing in `didDismissWithBlock:`
override func viewDidAppear(animated: Bool) {
if (!self.loginViewController.currentUser()) {
self.presentViewController(self.loginViewcontroller, animated: true, completion: nil)
}
}
// Scenario 2: User action launches login flow, dismissal and routing handled by `FirebaseLoginViewController`
func login() {
if (!self.loginViewController.currentUser()) {
self.presentViewController(self.loginViewcontroller, animated: true, completion: nil)
}
}
func logout() {
if (self.loginViewController.currentUser()) {
self.loginViewController.logout()
}
}
FirebaseFacebookAuthProvider
是Facebook登录的包装器。要启用此功能,请访问Firebase控制台中的认证选项卡,并选中复选框以启用此提供者,然后创建一个新的Facebook项目并遵循安装说明。您还必须在“Info.plist”中添加“FacebookAppID”和“FacebookDisplayName”键以及几个URL方案。有关设置信息的更多信息,请参阅Firebase Facebook认证文档。
Firebase *firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
FirebaseFacebookAuthProvider *facebookProvider = [[FirebaseFacebookAuthProvider alloc] initWithRef:firebaseRef authDelegate:self];
[facebookProvider login];
...
[facebookProvider logout];
let firebaseRef = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
let facebookProvider = FirebaseFacebookAuthProvider(ref: firebaseRef, authDelegate: self)
facebookProvider.login()
...
facebookProvider.logout()
FirebasTwitterAuthProvider是一个围绕Twitter登录的包装器。为了启用它,请访问Firebase仪表盘的认证标签页,勾选复选框以启用此提供者,然后创建一个新的Twitter项目,并在该页面上输入您的Twitter API密钥和密码。您还必须将键"TwitterApiKey"添加到您的应用"Info.plist"中。有关设置的更多信息,请参阅FirebaseTwitter认证文档。
Firebase *firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
FirebaseTwitterAuthProvider *twitterProvider = [[FirebaseTwitterAuthProvider alloc] initWithRef:firebaseRef authDelegate:self twitterDelegate:self];
[twitterProvider login];
...
[twitterProvider logout];
let firebaseRef = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
let twitterProvider = FirebaseTwitterAuthProvider(ref: firebaseRef, authDelegate: self, twitterDelegate: self)
twitterProvider.login()
...
twitterProvider.logout()
FirebasePasswordAuthProvider
是一个围绕Firebase电子邮件/密码登录的包装器。为了启用此功能,请访问Firebase仪表板的认证标签页,通过勾选复选框来启用此提供者。有关设置的更多信息,请参阅Firebase电子邮件/密码认证文档。
Firebase *firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
FirebasePasswordAuthProvider *passwordProvider = [[FirebasePasswordAuthProvider alloc] initWithRef:firebaseRef authDelegate:self];
[passwordProvider loginWithEmail:@"email" andPassword:@"password"];
...
[passwordProvider logout];
let firebaseRef = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
let passwordProvider = FirebasePasswordAuthProvider(ref: firebaseRef, authDelegate: self)
passwordProvider.login(email: "email", password: "password")
...
passwordProvider.login()
FirebaseAuthProvider
是所有身份提供者超类,提供默认构造函数[FirebaseAuthProvider initWithRef:authDelegate:]
以及login
,logout
和configureProvider
方法以简化跨提供者的标准认证。由于在基本实现中没有实现login
和configureProvider
方法,因此在调用时将抛出异常,因此每个提供者都应该重写这些方法。`logout
`已实现,用于取消给定Firebase引用的认证,并且始终应在任何子类实现的末尾用[super logout]
调用。
FirebaseAuthProvider
还注册了一个单例认证监听器,监控所有提供者的全局认证状态,并根据适当的路由authProvider:onLogin:
和onLogout
事件。
每个认证事件都通过FirebaseAuthDelegate
进行连接,它有四个方法:
[FirebaseAuthDelegate authProvider:onLogin:]
[FirebaseAuthDelegate onLogout:]
[FirebaseAuthDelegate authProvider:onUserError:]
[FirebaseAuthDelegate authProvider:onProviderError:]
前两个方法,登录和注销,对于实现FirebaseAuthDelegate
协议的类来说是必需的,而后两个方法是可选的,尽管强烈推荐。所有认证事件(无论提供者如何)都将通过这些方法进行。
一般来说,用户错误(如无效的密码或代表用户的认证请求取消)是可恢复的,并应提示用户重新进行认证,而提供者错误(例如配置不正确或提供者侧的问题)通常超出用户的控制,应引导用户走另一条路径(禁用提供者、临时禁用应用等)。
TwitterAuthDelegate
作为处理同一设备上零个或多个Twitter账户的特殊情况包括在内,因为开发者需要提示用户创建Twitter账户(或使用手机登录),或从多个账户中选择。可以用于这些目的的[TwitterAuthDelegate createTwitterAccount]
和[TwitterAuthDelegate selectTwitterAccount:]
方法。
FirebaseLoginViewController
是基于 FirebaseUI 认证组件构建的简单完整头部 UI 的一种实现。此类包含不同提供者的 Provider 方法以及关于当前提供者(因此是用户)的状态,这允许从外部视图控制器同步调用 currentUser
和 logout
,并将 FirebaseLoginViewController
作为认证状态的唯一真相来源。
FirebaseLoginViewController 中的所有 UI 元素都是可重新配置的(除了按钮颜色),因此根据您的应用程序配置 UI 不会很难。如果主题不合适,您可以自由地使用 FirebaseLoginViewController
的概念来创建自己的认证控制器。
此库是 FirebaseUI 的一个版本,移除了核心部分的 Google 集成,因此所有功劳都归功于 FirebaseUI。FireUInoGoogle 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。