Hướng dẫn di chuyển nhanh bằng tính năng Đăng nhập bằng Google
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này trình bày chi tiết những thay đổi quan trọng đối với các phiên bản chính của SDK Đăng nhập bằng Google.
Hãy làm theo hướng dẫn này để di chuyển ứng dụng của bạn sang phiên bản mới nhất của SDK Đăng nhập bằng Google. Xin lưu ý rằng tài liệu này luôn đề cập đến phiên bản mới nhất.
Ngoài ra, hãy tham khảo ghi chú phát hành và kho lưu trữ trên GitHub để biết thêm thông tin.
SDK Đăng nhập bằng Google phiên bản 7.0.0 trở lên
Để di chuyển ứng dụng của bạn từ phiên bản SDK Đăng nhập bằng Google trước phiên bản 7.0.0, hãy thực hiện các thay đổi sau:
Đặt cấu hình ứng dụng OAuth trong tệp Info.plist
của ứng dụng.
Bạn có thể tiếp tục đặt giá trị này trong thời gian chạy (bằng một đối tượng GIDConfiguration
), nhưng bạn không nên làm như vậy nữa. Hãy xem hướng dẫn bắt đầu để biết các ví dụ và thông tin chi tiết khác.
Phương thức addScopes:
đã được chuyển sang GIDGoogleUser. Thay vì yêu cầu phạm vi uỷ quyền bổ sung từ GIDSignIn, giờ đây, bạn nên yêu cầu phạm vi uỷ quyền từ GIDGoogleUser sau khi quá trình xác thực hoàn tất.
Nếu bạn đang thiết lập serverClientID
để bật quyền truy cập API phía máy chủ cho
ứng dụng của mình, thì serverAuthCode
sẽ được trả về cùng với GIDSignInResult
khi hoàn tất.
Các thuộc tính từ GIDAuthentication
đã chuyển vào GIDGoogleUser
.
Cập nhật lệnh gọi phương thức:
v6.2.x |
Phiên bản 7.0.0 trở lên |
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:
|
SDK đăng nhập bằng Google phiên bản 6.0.0
Để di chuyển ứng dụng của bạn từ phiên bản SDK Đăng nhập bằng Google trước phiên bản 6.0.0, hãy thực hiện các thay đổi sau:
Cập nhật tất cả lệnh gọi [GIDSignIn sharedInstance]
thành quyền truy cập thuộc tính GIDSignIn.sharedInstance
.
Di chuyển tất cả cấu hình ứng dụng (mã ứng dụng, v.v.) sang đối tượng GIDConfiguration
.
Cập nhật lệnh gọi của các phương thức đã xoá thành phương thức tương đương mới:
v5.x.x |
v6.0.0 |
signIn |
signInWithConfiguration:presentingViewController:callback: |
restorePreviousSignIn |
restorePreviousSignInWithCallback: |
disconnect |
disconnectWithCallback: |
getTokensWithHandler: |
doWithFreshTokens: |
refreshTokensWithHandler: |
doWithFreshTokens: |
Xoá mọi tham chiếu đến giao thức GIDSignInDelegate
và các phương thức của giao thức đó.
Di chuyển logic từ signIn:didSignInForUser:withError:
sang khối lệnh gọi lại của signInWithConfiguration:presentingViewController:callback:
.
Di chuyển logic từ signIn:didDisconnectWithUser:withError:
sang khối lệnh gọi lại của disconnectWithCallback:
.
Kết nối GIDSignInButton
theo cách thủ công với phương thức gọi signInWithConfiguration:presentingViewController:callback:
bằng IBAction
hoặc các phương thức tương tự.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eThis page provides migration guides for updating your app to the latest Google Sign-In SDK versions (v7.0.0+ and v6.0.0).\u003c/p\u003e\n"],["\u003cp\u003eFor v7.0.0+, OAuth client configuration should be set in \u003ccode\u003eInfo.plist\u003c/code\u003e, additional scopes are requested from \u003ccode\u003eGIDGoogleUser\u003c/code\u003e, and various properties and methods have been moved or updated.\u003c/p\u003e\n"],["\u003cp\u003eMigrating to v6.0.0 involves using \u003ccode\u003eGIDConfiguration\u003c/code\u003e for client configuration, updating method calls, and replacing \u003ccode\u003eGIDSignInDelegate\u003c/code\u003e with callback blocks.\u003c/p\u003e\n"],["\u003cp\u003eDetailed information and examples are available in linked resources like release notes, GitHub repository, and the "Get Started" guide.\u003c/p\u003e\n"]]],[],null,["# Google Sign-In quick migration guide\n\nThis page details key changes for major versions of the Google Sign-In SDK.\n\nFollow this guide to migrate your app to the latest version of the Google\nSign-In SDK. Note that the documentation always refers to the most recent\nversion.\n\nAlso refer to the [release notes](/identity/sign-in/ios/release) and the\n[repository on GitHub](https://github.com/google/GoogleSignIn-iOS)\nfor more information.\n\nGoogle Sign-In SDK v7.0.0+\n--------------------------\n\nTo migrate your app from a version of the Google Sign-In SDK prior to v7.0.0,\nmake the following changes:\n\n- Set your OAuth client configuration in your application's `Info.plist` file.\n You can continue to set it at runtime (using a `GIDConfiguration`) object,\n but this is no longer recommended. See the [get\n started](/identity/sign-in/ios/start-integrating#configure_app_project) guide for\n examples and more details.\n\n | `Info.plist` key | Description |\n |---------------------|-------------------------------------------------------------------------------------------------------------------|\n | `GIDClientID` | [OAuth client ID](/identity/sign-in/ios/start-integrating#add_client_id) |\n | `GIDServerClientID` | [Server OAuth client ID for backend authentication](/identity/sign-in/ios/start-integrating#add_server_client_id) |\n | `GIDHostedDomain` | [Google Workspace domain](/identity/sign-in/ios/start-integrating#add_domain_realm) |\n | `GIDOpenIDRealm` | [OpenID realm](/identity/sign-in/ios/start-integrating#add_domain_realm) |\n\n- The `addScopes:` method has been moved to GIDGoogleUser. Instead of\n requesting additional authorization scopes from GIDSignIn, you should now\n [request them from GIDGoogleUser after authentication](/identity/sign-in/ios/api-access#2_request_additional_scopes)\n has completed.\n\n- If you are setting `serverClientID` to [enable server-side API access for\n your app](/identity/sign-in/ios/offline-access), `serverAuthCode` will now be\n returned with `GIDSignInResult` in your completion.\n\n- Properties from `GIDAuthentication` have moved into `GIDGoogleUser`.\n\n- Update method calls:\n\n| v6.2.x | v7.0.0+ |\n|--------------------------------------------------------------------------|------------------------------------------------------------------|\n| `GIDSignIn` `signInWithConfiguration:presentingViewController:callback:` | `GIDSignIn` `signInWithPresentingViewController:completion:` |\n| `GIDSignIn` `restorePreviousSignInWithCallback:` | `GIDSignIn` `restorePreviousSignInWithCompletion:` |\n| `GIDSignIn` `disconnectWithCallback:` | `GIDSignIn` `disconnectWithCompletion:` |\n| `GIDAuthentication` `doWithFreshTokens:` | `GIDGoogleUser` `refreshTokensIfNeededWithCompletion:` |\n| `GIDSignIn` `addScopes:presentingViewController:callback:` | `GIDGoogleUser` `addScopes:presentingViewController:completion:` |\n\nGoogle Sign-In SDK v6.0.0\n-------------------------\n\nTo migrate your app from a version of the Google Sign-In SDK prior to v6.0.0,\nmake the following changes:\n\n- Update all `[GIDSignIn sharedInstance]` calls to `GIDSignIn.sharedInstance`\n property accesses.\n\n- Move all client configuration (client IDs, etc.) to a `GIDConfiguration`\n object.\n\n- Update calls to removed methods to their new equivalents:\n\n | v5.x.x | v6.0.0 |\n |-----------------------------|--------------------------------------------------------------|\n | `signIn` | `signInWithConfiguration:presentingViewController:callback:` |\n | `restorePreviousSignIn` | `restorePreviousSignInWithCallback:` |\n | `disconnect` | `disconnectWithCallback:` |\n | `getTokensWithHandler:` | `doWithFreshTokens:` |\n | `refreshTokensWithHandler:` | `doWithFreshTokens:` |\n\n- Remove all references to the `GIDSignInDelegate` protocol and its methods.\n\n - Move the logic from `signIn:didSignInForUser:withError:` to the callback\n block of `signInWithConfiguration:presentingViewController:callback:`.\n\n - Move the logic from `signIn:didDisconnectWithUser:withError:` to the\n callback block of `disconnectWithCallback:`.\n\n- Manually connect `GIDSignInButton` to a method that calls\n `signInWithConfiguration:presentingViewController:callback:` using an\n `IBAction` or similar."]]