18
18
#import < GoogleSignIn/GIDGoogleUser.h>
19
19
#import < GoogleSignIn/GIDProfileData.h>
20
20
#import < GoogleSignIn/GIDSignIn.h>
21
+ #import < UnityAppController.h>
22
+
23
+ #import " UnityInterface.h"
21
24
22
25
#import < memory>
23
26
@@ -59,6 +62,19 @@ void UnpauseUnityPlayer() {
59
62
60
63
@implementation GoogleSignInHandler
61
64
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
+
62
78
/* *
63
79
* Overload the presenting of the UI so we can pause the Unity player.
64
80
*/
@@ -105,9 +121,6 @@ - (void)signIn:(GIDSignIn *)signIn
105
121
case kGIDSignInErrorCodeKeychain :
106
122
currentResult_->result_code = kStatusCodeInternalError ;
107
123
break ;
108
- case kGIDSignInErrorCodeNoSignInHandlersInstalled :
109
- currentResult_->result_code = kStatusCodeDeveloperError ;
110
- break ;
111
124
case kGIDSignInErrorCodeHasNoAuthInKeychain :
112
125
currentResult_->result_code = kStatusCodeError ;
113
126
break ;
@@ -146,6 +159,7 @@ - (void)signIn:(GIDSignIn *)signIn
146
159
* The parameters are intended to be primative, easy to marshall.
147
160
*/
148
161
extern " C" {
162
+
149
163
/* *
150
164
* This method does nothing in the iOS implementation. It is here
151
165
* to make the API uniform between Android and iOS.
@@ -168,31 +182,29 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
168
182
bool requestIdToken, bool hidePopups,
169
183
const char **additionalScopes, int scopeCount,
170
184
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;
185
201
}
186
202
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
+ }
194
206
195
- return !useGameSignIn;
207
+ return !useGameSignIn;
196
208
}
197
209
198
210
/* *
@@ -226,7 +238,12 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
226
238
void *GoogleSignIn_SignIn () {
227
239
SignInResult *result = startSignIn ();
228
240
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
+ }];
230
247
result = currentResult_.get ();
231
248
}
232
249
return result;
@@ -239,7 +256,9 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
239
256
void *GoogleSignIn_SignInSilently () {
240
257
SignInResult *result = startSignIn ();
241
258
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
+ }];
243
262
result = currentResult_.get ();
244
263
}
245
264
return result;
@@ -252,7 +271,9 @@ void GoogleSignIn_Signout() {
252
271
253
272
void GoogleSignIn_Disconnect () {
254
273
GIDSignIn *signIn = [GIDSignIn sharedInstance ];
255
- [signIn disconnect ];
274
+ [signIn disconnectWithCallback: ^(NSError *error) {
275
+ [[GoogleSignInHandler sharedInstance ] signIn: [GIDSignIn sharedInstance ] didDisconnectWithUser: nil withError: error];
276
+ }];
256
277
}
257
278
258
279
bool GoogleSignIn_Pending (SignInResult *result) {
0 commit comments