重要提示:自
2024 年 5 月 1 日起,对于使用常用 SDK(包括 GoogleSignIn-iOS)的 iOS 应用,Apple
要求提供隐私权清单和签名。请在 2024 年 5 月 1 日之前升级到 GoogleSignIn-iOS v7.1.0 及更高版本。按照
我们的升级指南操作。
撤消访问令牌并断开应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
我们强烈建议您向使用 Google 账号登录的用户提供
取消其 Google 账号与您的应用的关联。如果用户删除
您必须删除您的应用从
Google API。
以下代码示例演示了如何以编程方式撤消访问权限
令牌,以及断开与
用户的账号。
Swift
GIDSignIn.sharedInstance.disconnect { error in
guard error == nil else { return }
// Google Account disconnected from your app.
// Perform clean-up actions, such as deleting data associated with the
// disconnected account.
}
Objective-C
[GIDSignIn.sharedInstance disconnectWithCompletion:^(NSError * _Nullable error) {
if (error) { return; }
// Google Account disconnected from your app.
// Perform clean-up actions, such as deleting data associated with the
// disconnected account.
}];
disconnectWithCompletion:
方法不仅会使用户退出登录,
断开其账号并撤销令牌。您不得将用户退出登录
然后再调用 disconnectWithCompletion:
。
然后,您可以在回调块内响应成功断开连接的操作
并在您的应用或后端代码中触发任何适当的逻辑。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eApps should allow users who signed in with Google to disconnect their Google account.\u003c/p\u003e\n"],["\u003cp\u003eUpon account deletion, app developers must delete user data obtained via Google APIs.\u003c/p\u003e\n"],["\u003cp\u003eProvided code snippets (Swift & Objective-C) show how to revoke access tokens and disconnect a user's Google account.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003edisconnectWithCompletion:\u003c/code\u003e handles sign-out, disconnection, and token revocation - do not sign the user out beforehand.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should implement logic within the callback to handle successful disconnections and trigger necessary actions.\u003c/p\u003e\n"]]],[],null,["# Revoking access tokens and disconnecting the app\n\nIt is highly recommended that you provide users that signed in with Google the\nability to disconnect their Google account from your app. If the user deletes\ntheir account, you must delete the information that your app obtained from the\nGoogle APIs.\n\nThe following code example demonstrates how to programmatically revoke access\ntokens that your app was granted on behalf of the user and to disconnect the\nuser's account from your app. \n\n### Swift\n\n GIDSignIn.sharedInstance.disconnect { error in\n guard error == nil else { return }\n\n // Google Account disconnected from your app.\n // Perform clean-up actions, such as deleting data associated with the\n // disconnected account.\n }\n\n### Objective-C\n\n [GIDSignIn.sharedInstance disconnectWithCompletion:^(NSError * _Nullable error) {\n if (error) { return; }\n\n // Google Account disconnected from your app.\n // Perform clean-up actions, such as deleting data associated with the\n // disconnected account.\n }];\n\nThe `disconnectWithCompletion:` method signs the user out in addition to\ndisconnecting their account and revoking tokens. You must not sign the user out\nbefore calling `disconnectWithCompletion:`.\n\nYou can then respond to the successful disconnection within the callback block\nand trigger any appropriate logic in your app or your back-end code."]]