iOS 上 Firebase Google 登录
复制一个包含安装步骤和本插件的完整Markdown指南的设置命令。
本指南将帮助您在iOS上将Google Sign-In与Firebase Authentication集成。假设您已经完成了相关步骤。 Firebase Google 通用设置.
设置步骤
标题为“设置步骤”-
前往您的项目概览 console.cloud.google.com
-
点击
Add appFirebase 添加应用按钮
-
选择
iOS
-
填写表单的第一部分
- 填写
Apple bundle ID- 打开 Xcode 并在您的应用中使用
npx cap open ios - 双击 Xcode 项目导航器中的 App 目标
App
- Capgo
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.cloud.google.com
-
找到您的项目
- 点击项目选择器
- 通过您的 Firebase 项目的准确名称搜索您的项目并点击它。我的情况是
sociallogin-tutorial-app.
- 点击项目选择器
-
打开搜索栏
credentials- 打开搜索栏
- 在
credentials中搜索并点击APIs and Services截图中第2个
- 打开搜索栏
-
点击
iOS client for [YOUR_APP_ID] (auto created by Google Service)截图中第2个。我的情况是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 控制台并转到
-
修改您的应用程序的 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 方案
-
-
步骤 9 中复制的 iOS 客户端 ID
YOUR_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中创建。
故障排除
标题为“故障排除”如果身份验证卡住或失败:
- 验证
idToken您的Firebase web客户端ID与 - 检查 Firebase 控制台中是否启用了 Google Sign-In
- 确保 Info.plist 中的 URL schemes 和 GIDClientID 与您的 web 客户端 ID 匹配
- 验证
iOSServerClientId与您的 web 客户端 ID 匹配 - 查看示例应用 __CAPGO_KEEP_0__ example app code 继续使用 Firebase Google Login on iOS
iOS 中从 Firebase Google Login 继续
如果您正在使用Firebase Google Login on iOS 来规划身份验证和帐户流程,连接它以实现身份验证和帐户流程 连接它以实现身份验证和帐户流程 使用 @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, 和 双因素认证 为实现细节在双因素认证.