本页详细介绍了 Google 登录 SDK 主要版本的主要变更。
按照本指南将您的应用迁移到最新版本的 Google 登录 SDK。请注意,文档始终引用最新版本。
如需了解详情,另请参阅版本说明和 GitHub 上的代码库。
Google 登录 SDK v7.0.0
如需从 7.0.0 之前的 Google 登录 SDK 版本迁移您的应用,请进行以下更改:
在应用的
Info.plist
文件中设置 OAuth 客户端配置。您可以在运行时(使用GIDConfiguration
)对象继续设置此字段,但现在不建议这样做。如需查看示例和更多详细信息,请参阅入门指南。Info.plist
密钥说明 GIDClientID
OAuth 客户端 ID GIDServerClientID
用于后端身份验证的服务器 OAuth 客户端 ID GIDHostedDomain
Google Workspace 网域 GIDOpenIDRealm
OpenID 领域 addScopes:
方法已移至 GIDGoogleUser。现在,您应该在完成身份验证后向 GIDGoogleUser 请求授权范围,而不是向 GIDSignIn 请求额外的授权范围。如果您将
serverClientID
设置为为您的应用启用服务器端 API 访问权限,那么现在,完成时serverAuthCode
将返回GIDSignInResult
。GIDAuthentication
中的属性已移至GIDGoogleUser
。更新方法调用:
6.2.x 版 | 7.0.0 版 |
---|---|
GIDSignIn
signInWithConfiguration:presentingViewController:callback:
|
GIDSignIn
signInWithPresentingViewController:completion:
|
GIDSignIn
restorePreviousSignInWithCallback:
|
GIDSignIn
restorePreviousSignInWithCompletion:
|
GIDSignIn
disconnectWithCallback:
|
GIDSignIn
disconnectWithCompletion:
|
GIDAuthentication
doWithFreshTokens:
|
GIDGoogleUser
refreshTokensIfNeededWithCompletion:
|
GIDSignIn
addScopes:presentingViewController:callback:
|
GIDGoogleUser
addScopes:presentingViewController:completion:
|
Google 登录 SDK v6.0.0
如需从 6.0.0 之前的 Google 登录 SDK 版本迁移您的应用,请进行以下更改:
更新对
GIDSignIn.sharedInstance
属性访问的所有[GIDSignIn sharedInstance]
调用。将所有客户端配置(客户端 ID 等)移至
GIDConfiguration
对象。将已移除方法的调用更新为新的等效方法:
5.x 版 6.0.0 版 signIn
signInWithConfiguration:presentingViewController:callback:
restorePreviousSignIn
restorePreviousSignInWithCallback:
disconnect
disconnectWithCallback:
getTokensWithHandler:
doWithFreshTokens:
refreshTokensWithHandler:
doWithFreshTokens:
移除对
GIDSignInDelegate
协议及其方法的所有引用。将逻辑从
signIn:didSignInForUser:withError:
移至signInWithConfiguration:presentingViewController:callback:
的回调块。将逻辑从
signIn:didDisconnectWithUser:withError:
移至disconnectWithCallback:
的回调块。
手动将
GIDSignInButton
连接到使用IBAction
或类似方法调用signInWithConfiguration:presentingViewController:callback:
的方法。