GoogleSignIn Framework Reference

GIDSignIn

@interface GIDSignIn : NSObject

This class signs the user in with Google.

For reference, please see “Google Sign-In for iOS” at https://developers.google.com/identity/sign-in/ios

  • A 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 or nil if there is no signed-in user.

    Declaration

    Swift

    var currentUser: GIDGoogleUser? { get }

    Objective-C

    @property (nonatomic, readonly, nullable) GIDGoogleUser *currentUser;
  • This method should be called from your UIApplicationDelegate‘s application: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 if GIDSignIn handled this URL.

  • Checks if there is a previously authenticated user saved in keychain.

    Declaration

    Swift

    func hasPreviousSignIn() -> Bool

    Objective-C

    - (BOOL)hasPreviousSignIn;

    Return Value

    YES if there is a previously authenticated user saved in keychain.

  • Attempts to restore a previously authenticated user without interaction.

    Declaration

    Swift

    func restorePreviousSignIn(callback: GIDSignInCallback? = nil)

    Objective-C

    - (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback;

    Parameters

    callback

    The GIDSignInCallback block that is called on completion. This block will be called asynchronously on the main queue.

  • Starts an interactive sign-in flow using the provided configuration.

    The callback 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 the restorePreviousSignInWithCallback: method to restore a previous sign-in.

    Declaration

    Swift

    func signIn(with configuration: GIDConfiguration, presenting presentingViewController: UIViewController, callback: GIDSignInCallback? = nil)

    Objective-C

    - (void)signInWithConfiguration:(nonnull GIDConfiguration *)configuration
           presentingViewController:
               (nonnull UIViewController *)presentingViewController
                           callback:(nullable GIDSignInCallback)callback;

    Parameters

    configuration

    The configuration properties to be used for this flow.

    presentingViewController

    The view controller used to present SFSafariViewContoller on iOS 9 and 10 and to supply presentationContextProvider for ASWebAuthenticationSession on iOS 13+.

    callback

    The GIDSignInCallback block that is called on completion. This block will be called asynchronously on the main queue.

  • Starts an interactive sign-in flow using the provided configuration and a login hint.

    The callback 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 the restorePreviousSignInWithCallback: method to restore a previous sign-in.

    Declaration

    Swift

    func signIn(with configuration: GIDConfiguration, presenting presentingViewController: UIViewController, hint: String?, callback: GIDSignInCallback? = nil)

    Objective-C

    - (void)signInWithConfiguration:(nonnull GIDConfiguration *)configuration
           presentingViewController:
               (nonnull UIViewController *)presentingViewController
                               hint:(nullable NSString *)hint
                           callback:(nullable GIDSignInCallback)callback;

    Parameters

    configuration

    The configuration properties to be used for this flow.

    presentingViewController

    The view controller used to present SFSafariViewContoller on iOS 9 and 10 and to supply presentationContextProvider for ASWebAuthenticationSession 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.

    callback

    The GIDSignInCallback block that is called on completion. This block will be called asynchronously on the main queue.

  • Starts an interactive consent flow to add scopes to the current user’s grants.

    The callback will be called at the end of this process. If successful, a new GIDGoogleUser instance will be returned reflecting the new scopes and saved sign-in state will be updated.

    Declaration

    Swift

    func addScopes(_ scopes: [String], presenting presentingViewController: UIViewController, callback: GIDSignInCallback? = nil)

    Objective-C

    - (void)addScopes:(nonnull NSArray<NSString *> *)scopes
        presentingViewController:
            (nonnull UIViewController *)presentingViewController
                        callback:(nullable GIDSignInCallback)callback;

    Parameters

    scopes

    The scopes to ask the user to consent to.

    presentingViewController

    The view controller used to present SFSafariViewContoller on iOS 9 and 10 and to supply presentationContextProvider for ASWebAuthenticationSession on iOS 13+.

    callback

    The GIDSignInCallback block that is called on completion. This block will be called asynchronously on the main queue.

  • Marks current user as being in the signed out state.

    Declaration

    Swift

    func signOut()

    Objective-C

    - (void)signOut;
  • Disconnects the current user from the app and revokes previous authentication. If the operation succeeds, the OAuth 2.0 token is also removed from keychain.

    Declaration

    Swift

    func disconnect(callback: GIDDisconnectCallback? = nil)

    Objective-C

    - (void)disconnectWithCallback:(nullable GIDDisconnectCallback)callback;

    Parameters

    callback

    The optional GIDDisconnectCallback block that is called on completion. This block will be called asynchronously on the main queue.