GIDSignIn
@interface GIDSignIn : NSObject
This class signs the user in with Google. It also provides single sign-on via a capable Google app if one is installed.
For reference, please see Google Sign-In for iOS
at
https://developers.google.com/identity/sign-in/ios
Here is sample code to use GIDSignIn
:
- Get a reference to the
GIDSignIn
shared instance:GIDSignIn *signIn = [GIDSignIn sharedInstance];
- Call
[signIn setDelegate:self]
; - Set up delegate method
signIn:didSignInForUser:withError:
. - Call
handleURL
on the shared instance fromapplication:openUrl:...
in your app delegate. - Call
signIn
on the shared instance;
-
The authentication object for the current user, or
nil
if there is currently no logged in user.Declaration
Swift
var currentUser: GIDGoogleUser! { get }
Objective-C
@property (readonly, nonatomic) GIDGoogleUser *currentUser;
-
The object to be notified when authentication is finished.
Declaration
Swift
weak var delegate: GIDSignInDelegate! { get set }
Objective-C
@property (readwrite, nonatomic) id<GIDSignInDelegate> delegate;
-
The view controller used to present
SFSafariViewContoller
on iOS 9 and 10.Declaration
Swift
weak var presentingViewController: UIViewController! { get set }
Objective-C
@property (readwrite, nonatomic) UIViewController *presentingViewController;
-
The client ID of the app from the Google APIs console. Must set for sign-in to work.
Declaration
Swift
var clientID: String! { get set }
Objective-C
@property (readwrite, copy, nonatomic) NSString *clientID;
-
The API scopes requested by the app in an array of
NSString
s. The default value is@[]
.This property is optional. If you set it, set it before calling
signIn
.Declaration
Swift
var scopes: [Any]! { get set }
Objective-C
@property (readwrite, copy, nonatomic) NSArray *scopes;
-
Whether or not to fetch basic profile data after signing in. The data is saved in the
GIDGoogleUser.profileData
object.Setting the flag will add
email
andprofile
to scopes. Defaults toYES
.Declaration
Swift
var shouldFetchBasicProfile: Bool { get set }
Objective-C
@property (assign, readwrite, nonatomic) BOOL shouldFetchBasicProfile;
-
The language for sign-in, in the form of ISO 639-1 language code optionally followed by a dash and ISO 3166-1 alpha-2 region code, such as
@"it"
or@"pt-PT"
. Only set if different from system default.This property is optional. If you set it, set it before calling
signIn
.Declaration
Swift
var language: String! { get set }
Objective-C
@property (readwrite, copy, nonatomic) NSString *language;
-
The login hint to the authorization server, for example the user’s ID, or email address, to be prefilled if possible.
This property is optional. If you set it, set it before calling
signIn
.Declaration
Swift
var loginHint: String! { get set }
Objective-C
@property (readwrite, copy, nonatomic) NSString *loginHint;
-
The client ID of the home web server. This will be returned as the
audience
property of the OpenID Connect ID token. For more info on the ID token: https://developers.google.com/identity/sign-in/ios/backend-authThis property is optional. If you set it, set it before calling
signIn
.Declaration
Swift
var serverClientID: String! { get set }
Objective-C
@property (readwrite, copy, nonatomic) NSString *serverClientID;
-
The OpenID2 realm of the home web server. This allows Google to include the user’s OpenID Identifier in the OpenID Connect ID token.
This property is optional. If you set it, set it before calling
signIn
.Declaration
Swift
var openIDRealm: String! { get set }
Objective-C
@property (readwrite, copy, nonatomic) NSString *openIDRealm;
-
The Google Apps domain to which users must belong to sign in. To verify, check
GIDGoogleUser
‘shostedDomain
property.This property is optional. If you set it, set it before calling
signIn
.Declaration
Swift
var hostedDomain: String! { get set }
Objective-C
@property (readwrite, copy, nonatomic) NSString *hostedDomain;
-
Returns a shared
GIDSignIn
instance.Declaration
Swift
class func sharedInstance() -> GIDSignIn!
Objective-C
+ (GIDSignIn *)sharedInstance;
-
Unavailable. Use
sharedInstance
to instantiateGIDSignIn
.Declaration
Objective-C
+ (instancetype)new;
-
Unavailable. Use
sharedInstance
to instantiateGIDSignIn
.Declaration
Objective-C
- (instancetype)init;
-
This method should be called from your
UIApplicationDelegate
‘sapplication:openURL:options
andapplication:openURL:sourceApplication:annotation
method(s).Declaration
Swift
func handle(_ url: URL!) -> Bool
Objective-C
- (BOOL)handleURL:(NSURL *)url;
Parameters
url
The URL that was passed to the app.
Return Value
YES
ifGIDSignIn
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. -
The delegate will be called at the end of this process indicating success or failure. The current values of
GIDSignIn
‘s configuration properties will not impact the restored user.Declaration
Swift
func restorePreviousSignIn()
Objective-C
- (void)restorePreviousSignIn;
-
Starts an interactive sign-in flow using
GIDSignIn
‘s configuration properties.The delegate 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 therestorePreviousSignIn
method to restore a previous sign-in.Declaration
Swift
func signIn()
Objective-C
- (void)signIn;
-
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()
Objective-C
- (void)disconnect;