Swift4 Day78:App的Google登入手把手教學
Swift4 / iOS11 / 2017.02.10
簡單設定所有UI
Firebase
填好資料快速註冊,建立,下載好GoogleService-Info.plist,我以前都直接丟到Xcode,要用App File to的方式加上比較不會有問題。可以到Copy Bundle Resources確認,如果沒有看到GoogleService-Info.plist,會crash。難怪我以前常常..QQ
新增 Firebase SDK
在AppDelegate加上import Firebase跟FirebaseApp.configure()
Set up delegate functions in App Delegate
Google文件:Get Started with Firebase Authentication on iOS
import GoogleSignIn
複製REVERSED_CLIENT_ID
貼到URL Types的URL Schemes
跟著文件寫上以下function
用實機測試之後旁邊就會print出用戶名稱跟mail
signInSilently()只要登入過一次就可以快速登入,不用再按button
在printe mailLabel跟nameLabel做修改
就可以直接在頁面上讀取到名字與mail
強大的firebase後台就可以看到剛剛登入的用戶資料
Resources
Google Sign In Documentation
https://firebase.google.com/docs/auth/ios/google-signin?authuser=0
Firebase Website
感覺是做App時很常見的功能,可以自己試試看~有問題可以留言在下方