Hec*_*zos 5 google-authentication ios firebase firebase-authentication swift4
我正在按照 Firebase 官方频道 ( https://firebase.google.com/docs/auth/ios/google-signin?hl=en-419 )的说明使用 Google 身份验证订阅我的应用。问题出现在函数中
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
Run Code Online (Sandbox Code Playgroud)
它没有从命令解析标识符 GoogleAuthProvider 和 Auth 的地方。即“使用未解析的标识符‘GoogleAuthProvider’”
let credential = GoogleAuthProvider.credential(idToken: authentication.idToken, accessToken: authentication.accessToken)
// ...
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
// ...
return
}
Run Code Online (Sandbox Code Playgroud)
我在查看器和 AppDelegate 中都导入了:
import Firebase
import GoogleSignIn
Run Code Online (Sandbox Code Playgroud)
我的 Podfile 看起来像这样:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'racc' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for racc
pod 'Firebase/Core'
pod 'GoogleSignIn'
pod 'Firebase/Auth'
target 'raccTests' do
inherit! :search_paths
# Pods for testing
end
end
Run Code Online (Sandbox Code Playgroud)
我在 Swift 4 工作
小智 7
您需要导入FirebaseAuth到您的 App Delegate 中。
在您的 Podfile 中:
pod 'Firebase/Auth'
在您的 AppDelegate 中:
import FirebaseAuth
Google 官方说明中缺少这些步骤。
您的 Firebase 仪表板中很可能没有启用 Google Login。要启用,请转到 Firebase 仪表板,然后单击您的项目。
从那里,点击身份验证和登录方法。找到 Google,然后点击启用。