Firebase Google 登录 iOS
复制一个带有安装步骤和完整 Markdown 指南的设置提示。
本指南将帮助您在 iOS 上将 Google Sign-In 与 Firebase Authentication 集成。假设您已经完成了 通用 Firebase Google 设置.
设置步骤
标题为“设置步骤”-
前往您的项目概览页面,地址为 console.cloud.google.com
-
点击
Add app按钮
-
选择
iOS
-
填写表单的第一部分
- 填写
Apple bundle ID- 在 Xcode 中打开您的应用
npx cap open ios - 双击 Xcode 项目导航器中的 App 目标
App
- 在 Xcode Targets 部分中选中 App
Targets -> App
- 找到你的
Bundle Identifier
- 复制
Bundle Identifier并粘贴到Firebase控制台
- 在 Xcode 中打开您的应用
- 点击
Register app按钮
- 填写
-
跳过
Download config file步骤
-
跳过
Add firebase SDK步骤
-
跳过
Add initialization code步骤
-
点击
Continue to console按钮
-
获取您的iOS客户端ID和您的
YOUR_DOT_REVERSED_IOS_CLIENT_ID-
前往Google Cloud Console console.cloud.google.com
-
找到您的项目
- 点击项目选择器
- 通过您的Firebase项目的准确名称搜索您的项目并点击它。在我的情况下,它是
sociallogin-tutorial-app.
- 点击项目选择器
-
打开搜索栏并打开
credentials- 打开搜索栏
- 搜索
credentials点击并选择APIs and Services截图中第 2 项
- 打开搜索栏
-
点击
iOS client for [YOUR_APP_ID] (auto created by Google Service)截图中第 1 项。在我的情况下是sociallogin-tutorial-app.
-
复制
Client ID以及iOS URL scheme。这将分别是你的iOSClientId和YOUR_DOT_REVERSED_IOS_CLIENT_ID.
-
-
获取您的 Web 客户端 ID
- 返回到 Firebase 控制台并转到
Build->Authentication
- 点击
Sign-in method按钮
- 点击
Google服务提供商
- 点击
Web SDK configuration按钮
- 复制
Web client ID. 这将是你的webClientId在initialize插件的方法中.
- 返回到 Firebase 控制台并转到
-
修改你的 app 的 Info.plist
-
打开 Xcode 并在 Xcode 项目导航器中找到文件
Info.plist__CAPGO_KEEP_0__
-
右键点击此文件并以源代码形式打开 code
-
您的文件底部会看到一个
PlistInfo.plist 文件中的</dict>Info.plist 文件中的
-
Info.plist 文件中插入以下片段,紧接着关闭
</dict>Info.plist 文件中插入 URL 方案 __CAPGO_KEEP_0__,紧接着关闭
<key>CFBundleURLTypes</key><array><dict><key>CFBundleURLSchemes</key><array><string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string></array></dict></array><key>GIDClientID</key><string>YOUR_IOS_CLIENT_ID.apps.googleusercontent.com</string> -
修改为
YOUR_DOT_REVERSED_IOS_CLIENT_ID修改为步骤 9 中复制的 iOS URL_scheme 值
-
-
修改为步骤 9 中复制的 iOS Client ID
YOUR_IOS_CLIENT_ID保存文件 -
确保这个值以
Command + S -
修改
AppDelegate.swift-
打开AppDelegate
-
在
import GoogleSignInAppDelegate.swift文件的顶部添加
-
找到
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:])函数
-
修改函数以如下方式
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {// Called when the app was launched with a url. Feel free to add additional processing here,// but if you want the App API to support tracking app url opens, make sure to keep this callvar handled: Boolhandled = GIDSignIn.sharedInstance.handle(url)if handled {return true}return ApplicationDelegateProxy.shared.application(app, open: url, options: options)}
-
保存文件为
Command + S
-
-
在您的应用程序中使用Google登录
您已经准备好在应用程序中使用Google登录。 请使用示例应用程序的 authUtils.ts 文件与Google进行身份验证。
在Firebase Auth中,用户将在首次登录时自动创建。
故障排除
标题为“故障排除”如果身份验证卡住或失败:
- 验证
idToken确保 - 与Firebase Web客户端ID匹配
- 确保 Info.plist 中的 URL 方案和 GIDClientID 正确
- 验证
iOSServerClientId与您的 Web 客户端 ID 匹配 - 查看 示例应用程序 code 以参考
继续 Firebase Google 登录
标题:继续 Firebase Google 登录如果您正在使用 Firebase Google 登录 来规划身份验证和帐户流程,连接它 使用 @capgo/capacitor-social-login 为使用@capgo/capacitor-social-login的原生能力 @capgo/capacitor-social-login @capgo/capacitor-social-login的实现细节 @capgo/capacitor-passkey @capgo/capacitor-passkey的实现细节 @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric的实现细节, 双因素认证 双因素认证的实现细节