AI-generated Key Takeaways
-
The GIDSignIn class is used to sign in users with their Google account and manage their session on iOS and macOS.
-
You can access the shared GIDSignIn instance and check for the current signed-in user.
-
The class provides methods to handle URLs, check for and restore previous sign-ins, and sign out or disconnect the current user.
-
Interactive sign-in flows can be started with different options for presenting the sign-in interface and specifying hints or additional scopes.
GIDSignIn
@interface GIDSignIn : NSObjectThis class is used to sign in users with their Google account and manage their session.
For reference, please see “Google Sign-In for iOS and macOS” at https://developers.google.com/identity/sign-in/ios
-
The shared
GIDSignIninstance.Declaration
Swift
class var sharedInstance: GIDSignIn { get }Objective-C
@property (class, nonatomic, readonly) GIDSignIn *_Nonnull sharedInstance; -
The
GIDGoogleUserobject representing the current user ornilif there is no signed-in user.Declaration
Swift
var currentUser: GIDGoogleUser? { get }Objective-C
@property (nonatomic, readonly, nullable) GIDGoogleUser *currentUser; -
The active configuration for this instance of
GIDSignIn.Declaration
Swift
var configuration: GIDConfiguration? { get set }Objective-C
@property (nonatomic, nullable) GIDConfiguration *configuration; -
This method should be called from your
UIApplicationDelegate‘sapplication:openURL:options:method.Declaration
Swift
func handle(_ url: URL) -> BoolObjective-C
- (BOOL)handleURL:(nonnull NSURL *)url;Parameters
urlThe URL that was passed to the app.
Return Value
YESifGIDSignInhandled this URL. -
Checks if there is a previous user sign-in saved in keychain.
Declaration
Swift
func hasPreviousSignIn() -> BoolObjective-C
- (BOOL)hasPreviousSignIn;Return Value
YESif there is a previous user sign-in saved in keychain. -
Attempts to restore a previous user sign-in without interaction.
Declaration
Swift
func restorePreviousSignIn() async throws -> GIDGoogleUserObjective-C
- (void)restorePreviousSignInWithCompletion: (nullable void (^)(GIDGoogleUser *_Nullable, NSError *_Nullable))completion;Parameters
completionThe block that is called on completion. This block will be called asynchronously on the main queue.
-
Signs out the
currentUser, removing it from the keychain.Declaration
Swift
func signOut()Objective-C
- (void)signOut; -
Disconnects the
currentUserby signing them out and revoking all OAuth2 scope grants made to the app.Declaration
Swift
func disconnect() async throwsObjective-C
- (void)disconnectWithCompletion: (nullable void (^)(NSError *_Nullable))completion;Parameters
completionThe optional block that is called on completion. This block will be called asynchronously on the main queue.
-
Starts an interactive sign-in flow on iOS.
The completion will be called at the end of this process. Any saved sign-in state will be replaced by the result of this flow. Note that this method should not be called when the app is starting up, (e.g in
application:didFinishLaunchingWithOptions:); instead use therestorePreviousSignInWithCompletion:method to restore a previous sign-in.Declaration
Swift
func signIn(withPresenting presentingViewController: UIViewController) async throws -> GIDSignInResultObjective-C
- (void)signInWithPresentingViewController: (nonnull UIViewController *)presentingViewController completion:(nullable void (^)( GIDSignInResult *_Nullable, NSError *_Nullable))completion;Parameters
presentingViewControllerThe view controller used to present
SFSafariViewContolleron iOS 9 and 10 and to supplypresentationContextProviderforASWebAuthenticationSessionon iOS 13+.completionThe optional block that is called on completion. This block will be called asynchronously on the main queue.
-
Starts an interactive sign-in flow on iOS using the provided hint.
The completion will be called at the end of this process. Any saved sign-in state will be replaced by the result of this flow. Note that this method should not be called when the app is starting up, (e.g in
application:didFinishLaunchingWithOptions:); instead use therestorePreviousSignInWithCompletion:method to restore a previous sign-in.Declaration
Swift
func signIn(withPresenting presentingViewController: UIViewController, hint: String?) async throws -> GIDSignInResultObjective-C
- (void)signInWithPresentingViewController: (nonnull UIViewController *)presentingViewController hint:(nullable NSString *)hint completion:(nullable void (^)( GIDSignInResult *_Nullable, NSError *_Nullable))completion;Parameters
presentingViewControllerThe view controller used to present
SFSafariViewContolleron iOS 9 and 10 and to supplypresentationContextProviderforASWebAuthenticationSessionon iOS 13+.hintAn optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
completionThe optional block that is called on completion. This block will be called asynchronously on the main queue.
-
Starts an interactive sign-in flow on iOS using the provided hint and additional scopes.
The completion will be called at the end of this process. Any saved sign-in state will be replaced by the result of this flow. Note that this method should not be called when the app is starting up, (e.g in
application:didFinishLaunchingWithOptions:); instead use therestorePreviousSignInWithCompletion:method to restore a previous sign-in.Declaration
Swift
func signIn(withPresenting presentingViewController: UIViewController, hint: String?, additionalScopes: [String]?) async throws -> GIDSignInResultObjective-C
- (void)signInWithPresentingViewController: (nonnull UIViewController *)presentingViewController hint:(nullable NSString *)hint additionalScopes: (nullable NSArray<NSString *> *)additionalScopes completion:(nullable void (^)( GIDSignInResult *_Nullable, NSError *_Nullable))completion;Parameters
presentingViewControllerThe view controller used to present
SFSafariViewContolleron iOS 9 and 10.hintAn optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
additionalScopesAn optional array of scopes to request in addition to the basic profile scopes.
completionThe optional block that is called on completion. This block will be called asynchronously on the main queue.
-
Starts an interactive sign-in flow on macOS.
The completion will be called at the end of this process. Any saved sign-in state will be replaced by the result of this flow. Note that this method should not be called when the app is starting up, (e.g in
application:didFinishLaunchingWithOptions:); instead use therestorePreviousSignInWithCompletion:method to restore a previous sign-in.Declaration
Swift
func signIn(withPresentingWindow presentingWindow: Any!) async throws -> GIDSignInResultObjective-C
- (void)signInWithPresentingWindow:(id)presentingWindow completion: (nullable void (^)(GIDSignInResult *_Nullable, NSError *_Nullable))completion;Parameters
presentingWindowThe window used to supply
presentationContextProviderforASWebAuthenticationSession.completionThe optional block that is called on completion. This block will be called asynchronously on the main queue.
-
Starts an interactive sign-in flow on macOS using the provided hint.
The completion will be called at the end of this process. Any saved sign-in state will be replaced by the result of this flow. Note that this method should not be called when the app is starting up, (e.g in
application:didFinishLaunchingWithOptions:); instead use therestorePreviousSignInWithCompletion:method to restore a previous sign-in.Declaration
Swift
func signIn(withPresentingWindow presentingWindow: Any!, hint: String?) async throws -> GIDSignInResultObjective-C
- (void)signInWithPresentingWindow:(id)presentingWindow hint:(nullable NSString *)hint completion: (nullable void (^)(GIDSignInResult *_Nullable, NSError *_Nullable))completion;Parameters
presentingWindowThe window used to supply
presentationContextProviderforASWebAuthenticationSession.hintAn optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
completionThe optional block that is called on completion. This block will be called asynchronously on the main queue.
-
Starts an interactive sign-in flow on macOS using the provided hint.
The completion will be called at the end of this process. Any saved sign-in state will be replaced by the result of this flow. Note that this method should not be called when the app is starting up, (e.g in
application:didFinishLaunchingWithOptions:); instead use therestorePreviousSignInWithCompletion:method to restore a previous sign-in.Declaration
Swift
func signIn(withPresentingWindow presentingWindow: Any!, hint: String?, additionalScopes: [String]?) async throws -> GIDSignInResultObjective-C
- (void)signInWithPresentingWindow:(id)presentingWindow hint:(nullable NSString *)hint additionalScopes: (nullable NSArray<NSString *> *)additionalScopes completion: (nullable void (^)(GIDSignInResult *_Nullable, NSError *_Nullable))completion;Parameters
presentingWindowThe window used to supply
presentationContextProviderforASWebAuthenticationSession.hintAn optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
additionalScopesAn optional array of scopes to request in addition to the basic profile scopes.
completionThe optional block that is called on completion. This block will be called asynchronously on the main queue.