好的,那就来看看firebase到底是什麽吧。
我们这次会用到firebase auth
的注册、登入功能;firebase real time database
的资料库服务;以及firebase storage
的云端硬碟。
那麽我们先来新增引用的函式库。
在Podfile新增以下的指令,然後下载。
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Analytics'
首先将auth函式库引进来
import FirebaseAuth
然後将昨天留下登入的部分补上逻辑
FirebaseAuth.Auth.auth().signIn(withEmail: email, password: password, completion: { authResult, error in
guard let result = authResult, error == nil else {
print("failed to login with email: \(email)")
return
}
let user = result.user
print("logged in user: \(user)")
})
firebase提供的登入服务非常方便,可以直接呼叫signIn
方法。
其中我们选用提供withEmail
参数的方法。
使用guard
确保登入成功,在此我们先印出成功登入的讯息,先不处理跳转等的东西。
同样的,我们也在注册这边加上firebase auth的服务逻辑。
FirebaseAuth.Auth.auth().createUser(withEmail: email, password: password, completion: { authResult, error in
guard let result = authResult, error == nil else {
print("error creating user")
return
}
let user = result.user
print("Create user: \(user)")
})
别忘了在appDelegate加上firebase auth的configuration。
如下第9行,如此一来,就大功告成了!
import UIKit
import Firebase
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
}
今天写的比较简短,且都是着墨在程序上,解释得较少(其实就是因为存稿用完了,开始每天赶稿的日子、呜呜呜)
不过写的短好过缺少文章麻~未来还是会继续努力产出的~
若上述内容有误或可以改进的部分,欢迎留言以及提出任何指教~
谢谢 (´・∀・`)
我想应该有许多 IT 邦帮忙的作者都很关心自己文章的浏览数,像笔者就是一个喜欢三不五时去看看自己文章...
目标 使用 Pro Components 制作图表 萤幕截图 汇出png图 Vaadin Chart...
iOS APP 开发 OC 第十四天,签证 tags: OC 30 day 资料来源:iOS 打包签...
宣告方式 var array_name = [length]datatype{values} var...
由於管理是实现一个或多个目标的系统方法,我根据维基百科和NIST CSRC 术语表中的定义定义漏洞...