iOS 上的 Firebase Google Login
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
本指南将帮助你在 iOS 上集成 Google 登录与 Firebase 身份验证。假设你已完成 Firebase Google 通用配置.
设置步骤
标题为“设置步骤”的章节-
前往您的项目概览页面 console.cloud.google.com
-
点击
Add app按钮
-
选择
iOS
-
填写表单的第一部分
- 填写
Apple bundle ID- 使用以下命令在 Xcode 中打开您的应用
npx cap open ios - 双击
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)一个。在我的情况下,它是sociallogin-tutorial-app.
-
复制
Client ID以及iOS URL scheme。这将分别作为您的iOSClientId以及YOUR_DOT_REVERSED_IOS_CLIENT_ID.
-
-
获取你的 Web Client ID
- 返回 Firebase 控制台并前往
Build->Authentication
- 点击
Sign-in method按钮
- 点击
Google提供方
- 点击
Web SDK configuration按钮
- 复制
Web client ID。这将是你的webClientId,详见initialize插件方法。
- 返回 Firebase 控制台并前往
-
修改应用的 Info.plist
-
打开 Xcode 并找到
Info.plist文件
-
右键单击此文件,选择“以源码打开 code”
-
在您的
Plist文件底部,您会看到</dict>标签
-
在闭合
</dict>标签
<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)
-
-
更改
YOUR_IOS_CLIENT_ID粘贴到您在第 9 步中复制的 iOS Client ID -
保存文件,内容如下
Command + S -
修改
AppDelegate.swift-
打开 AppDelegate
-
插入
import GoogleSignIn在文件顶部
-
找到
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 中自动创建
故障排除
“故障排除”章节如果身份验证卡住或失败:
- 请检查
idTokenaudience 与你的 Firebase Web 客户端 ID 匹配 - 检查 Firebase Console 中是否已启用 Google Sign-In
- 确保 Info.plist 包含正确的 URL schemes 和 GIDClientID
- 验证
iOSServerClientId与您的 Web 客户端 ID 匹配 - 请查阅 示例应用 code 仅供参考
从 iOS 版 Firebase Google Login 继续
标题为“从 iOS 版 Firebase Google Login 继续”的章节如果你正在使用 iOS 上的 Firebase Google Login 用来规划身份验证和账户流程,并将它与 使用 @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 中的实现细节, 双因素认证 有关双重身份验证的实现细节。