GIDSignIn
@interface GIDSignIn : NSObject
This 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
GIDSignIn
instance.Declaration
Swift
class var sharedInstance: GIDSignIn { get }
Objective-C
@property (class, nonatomic, readonly) GIDSignIn *_Nonnull sharedInstance;
-
The
GIDGoogleUser
object representing the current user ornil
if 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) -> Bool
Objective-C
- (BOOL)handleURL:(nonnull NSURL *)url;
Parameters
url
The URL that was passed to the app.
Return Value
YES
ifGIDSignIn
handled this URL. -
Checks if there is a previous user sign-in saved in keychain.
Declaration
Swift
func hasPreviousSignIn() -> Bool
Objective-C
- (BOOL)hasPreviousSignIn;
Return Value
YES
if 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 -> GIDGoogleUser
Objective-C
- (void)restorePreviousSignInWithCompletion: (nullable void (^)(GIDGoogleUser *_Nullable, NSError *_Nullable))completion;
Parameters
completion
The 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
currentUser
by signing them out and revoking all OAuth2 scope grants made to the app.Declaration
Swift
func disconnect() async throws
Objective-C
- (void)disconnectWithCompletion: (nullable void (^)(NSError *_Nullable))completion;
Parameters
completion
The 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 -> GIDSignInResult
Objective-C
- (void)signInWithPresentingViewController: (nonnull UIViewController *)presentingViewController completion:(nullable void (^)( GIDSignInResult *_Nullable, NSError *_Nullable))completion;
Parameters
presentingViewController
The view controller used to present
SFSafariViewContoller
on iOS 9 and 10 and to supplypresentationContextProvider
forASWebAuthenticationSession
on iOS 13+.completion
The 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 -> GIDSignInResult
Objective-C
- (void)signInWithPresentingViewController: (nonnull UIViewController *)presentingViewController hint:(nullable NSString *)hint completion:(nullable void (^)( GIDSignInResult *_Nullable, NSError *_Nullable))completion;
Parameters
presentingViewController
The view controller used to present
SFSafariViewContoller
on iOS 9 and 10 and to supplypresentationContextProvider
forASWebAuthenticationSession
on iOS 13+.hint
An optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
completion
The 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 -> GIDSignInResult
Objective-C
- (void)signInWithPresentingViewController: (nonnull UIViewController *)presentingViewController hint:(nullable NSString *)hint additionalScopes: (nullable NSArray<NSString *> *)additionalScopes completion:(nullable void (^)( GIDSignInResult *_Nullable, NSError *_Nullable))completion;
Parameters
presentingViewController
The view controller used to present
SFSafariViewContoller
on iOS 9 and 10.hint
An optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
additionalScopes
An optional array of scopes to request in addition to the basic profile scopes.
completion
The 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 -> GIDSignInResult
Objective-C
- (void)signInWithPresentingWindow:(id)presentingWindow completion: (nullable void (^)(GIDSignInResult *_Nullable, NSError *_Nullable))completion;
Parameters
presentingWindow
The window used to supply
presentationContextProvider
forASWebAuthenticationSession
.completion
The 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 -> GIDSignInResult
Objective-C
- (void)signInWithPresentingWindow:(id)presentingWindow hint:(nullable NSString *)hint completion: (nullable void (^)(GIDSignInResult *_Nullable, NSError *_Nullable))completion;
Parameters
presentingWindow
The window used to supply
presentationContextProvider
forASWebAuthenticationSession
.hint
An optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
completion
The 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 -> GIDSignInResult
Objective-C
- (void)signInWithPresentingWindow:(id)presentingWindow hint:(nullable NSString *)hint additionalScopes: (nullable NSArray<NSString *> *)additionalScopes completion: (nullable void (^)(GIDSignInResult *_Nullable, NSError *_Nullable))completion;
Parameters
presentingWindow
The window used to supply
presentationContextProvider
forASWebAuthenticationSession
.hint
An optional hint for the authorization server, for example the user’s ID or email address, to be prefilled if possible.
additionalScopes
An optional array of scopes to request in addition to the basic profile scopes.
completion
The optional block that is called on completion. This block will be called asynchronously on the main queue.