1818#import < GoogleSignIn/GIDGoogleUser.h>
1919#import < GoogleSignIn/GIDProfileData.h>
2020#import < GoogleSignIn/GIDSignIn.h>
21+ #import < UnityAppController.h>
22+
23+ #import " UnityInterface.h"
2124
2225#import < memory>
2326
@@ -59,6 +62,19 @@ void UnpauseUnityPlayer() {
5962
6063@implementation GoogleSignInHandler
6164
65+ GIDConfiguration* signInConfiguration = nil ;
66+ NSString * loginHint = nil ;
67+ NSMutableArray * additionalScopes = nil ;
68+
69+ + (GoogleSignInHandler *)sharedInstance {
70+ static dispatch_once_t once;
71+ static GoogleSignInHandler *sharedInstance;
72+ dispatch_once (&once, ^{
73+ sharedInstance = [self alloc ];
74+ });
75+ return sharedInstance;
76+ }
77+
6278/* *
6379 * Overload the presenting of the UI so we can pause the Unity player.
6480 */
@@ -105,9 +121,6 @@ - (void)signIn:(GIDSignIn *)signIn
105121 case kGIDSignInErrorCodeKeychain :
106122 currentResult_->result_code = kStatusCodeInternalError ;
107123 break ;
108- case kGIDSignInErrorCodeNoSignInHandlersInstalled :
109- currentResult_->result_code = kStatusCodeDeveloperError ;
110- break ;
111124 case kGIDSignInErrorCodeHasNoAuthInKeychain :
112125 currentResult_->result_code = kStatusCodeError ;
113126 break ;
@@ -146,6 +159,7 @@ - (void)signIn:(GIDSignIn *)signIn
146159 * The parameters are intended to be primative, easy to marshall.
147160 */
148161extern " C" {
162+
149163/* *
150164 * This method does nothing in the iOS implementation. It is here
151165 * to make the API uniform between Android and iOS.
@@ -168,31 +182,29 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
168182 bool requestIdToken, bool hidePopups,
169183 const char **additionalScopes, int scopeCount,
170184 const char *accountName) {
171- if (webClientId) {
172- [GIDSignIn sharedInstance ].serverClientID =
173- [NSString stringWithUTF8String: webClientId];
174- }
175-
176- [GIDSignIn sharedInstance ].shouldFetchBasicProfile = true ;
177-
178- int scopeSize = scopeCount;
179-
180- if (scopeSize) {
181- NSMutableArray *tmpary =
182- [[NSMutableArray alloc ] initWithCapacity: scopeSize];
183- for (int i = 0 ; i < scopeCount; i++) {
184- [tmpary addObject: [NSString stringWithUTF8String: additionalScopes[i]]];
185+ NSString *path = [[NSBundle mainBundle ] pathForResource: @" GoogleService-Info" ofType: @" plist" ];
186+ NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path];
187+ NSString *clientId = [dict objectForKey: @" CLIENT_ID" ];
188+ GIDConfiguration* config = [[GIDConfiguration alloc ] initWithClientID: clientId];
189+ if (webClientId) {
190+ config = [[GIDConfiguration alloc ] initWithClientID: clientId serverClientID: [NSString stringWithUTF8String: webClientId]];
191+ }
192+ [GoogleSignInHandler sharedInstance ]->signInConfiguration = config;
193+
194+ int scopeSize = scopeCount;
195+ if (scopeSize) {
196+ NSMutableArray *tmpary = [[NSMutableArray alloc ] initWithCapacity: scopeSize];
197+ for (int i = 0 ; i < scopeCount; i++) {
198+ [tmpary addObject: [NSString stringWithUTF8String: additionalScopes[i]]];
199+ }
200+ [GoogleSignInHandler sharedInstance ]->additionalScopes = tmpary;
185201 }
186202
187- [GIDSignIn sharedInstance ].scopes = tmpary;
188- }
189-
190- if (accountName) {
191- [GIDSignIn sharedInstance ].loginHint =
192- [NSString stringWithUTF8String: accountName];
193- }
203+ if (accountName) {
204+ [GoogleSignInHandler sharedInstance ]->loginHint = [NSString stringWithUTF8String: accountName];
205+ }
194206
195- return !useGameSignIn;
207+ return !useGameSignIn;
196208}
197209
198210/* *
@@ -226,7 +238,12 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
226238void *GoogleSignIn_SignIn () {
227239 SignInResult *result = startSignIn ();
228240 if (!result) {
229- [[GIDSignIn sharedInstance ] signIn ];
241+ [[GIDSignIn sharedInstance ] signInWithConfiguration: [GoogleSignInHandler sharedInstance ]->signInConfiguration
242+ presentingViewController: UnityGetGLViewController ()
243+ hint: [GoogleSignInHandler sharedInstance ]->loginHint
244+ callback: ^(GIDGoogleUser *user, NSError *error) {
245+ [[GoogleSignInHandler sharedInstance ] signIn: [GIDSignIn sharedInstance ] didSignInForUser: user withError: error];
246+ }];
230247 result = currentResult_.get ();
231248 }
232249 return result;
@@ -239,7 +256,9 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
239256void *GoogleSignIn_SignInSilently () {
240257 SignInResult *result = startSignIn ();
241258 if (!result) {
242- [[GIDSignIn sharedInstance ] signInSilently ];
259+ [[GIDSignIn sharedInstance ] restorePreviousSignInWithCallback: ^(GIDGoogleUser *user, NSError *error) {
260+ [[GoogleSignInHandler sharedInstance ] signIn: [GIDSignIn sharedInstance ] didSignInForUser: user withError: error];
261+ }];
243262 result = currentResult_.get ();
244263 }
245264 return result;
@@ -252,7 +271,9 @@ void GoogleSignIn_Signout() {
252271
253272void GoogleSignIn_Disconnect () {
254273 GIDSignIn *signIn = [GIDSignIn sharedInstance ];
255- [signIn disconnect ];
274+ [signIn disconnectWithCallback: ^(NSError *error) {
275+ [[GoogleSignInHandler sharedInstance ] signIn: [GIDSignIn sharedInstance ] didDisconnectWithUser: nil withError: error];
276+ }];
256277}
257278
258279bool GoogleSignIn_Pending (SignInResult *result) {
0 commit comments