实现谷歌登录功能
这篇文档将告诉你如何使用Google Sign-in SDK来实现登录功能并获取用户的基本信息
文档同时包含配置相关的内容以及代码相关的实现
Google Sign-In SDK的安装
- 使用用Cocoapods安装
| pod 'GoogleSignIn' |
|---|
- 使用Swift Package Manager进行安装
安装成功后import开始使用
| import GoogleSignIn |
|---|
为Google Sign-In创建OAuth Client ID
安装好SDK后,你将需要一个OAuth Client ID和一个iOS URL Scheme来配置Xcode
到Google APIs Console为你的app创建一个项目。如果你已经创建了,你可以从项目列表中找到它。
在创建或选择项目后,接下来到OAuth consent screen来选择app的user type然后创建OAuth consent screen。
如图所示:
在 OAuth consent screen页面,填好Application name然后保存。Application name将在用户登录时的Google Sign-in框中显示。
Once finished configuring the OAuth consent screen, it is time to create the OAuth client ID. You can follow the steps as shown in the image below to navigate to the OAuth client ID creation page.
在配置完OAuth同意屏幕,接下来开始创建OAuth client ID。如图所示。
在接下来,在 OAuth client ID创建页面,选择“iOS”作为Application type,填写一个名字并填写你app的bundle ID,然后点击创建。
接下来你将使用到Client ID和iOS URL scheme。
在完成了 OAuth client ID配置后,应该到Xcode进行下一步的操作。
在Xcode中配置Google Sign-In SDK
Google Sign-in需要加一个定制的URL Scheme到项目。根据如图所示的步骤,把刚刚创建的OS URL scheme添加到 iOS URL scheme(下图标记4的位置)。\