From aac32d99dae0b22daa0598ba89578e799c03f9df Mon Sep 17 00:00:00 2001 From: JokeMaker Date: Thu, 16 Dec 2021 11:26:32 +0800 Subject: [PATCH 1/2] Update Android version to 20+ & iOS to 6.0.2 --- .../Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml b/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml index 625d2e51..15ad7e70 100644 --- a/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml +++ b/GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml @@ -3,7 +3,7 @@ - + extra-google-m2repository @@ -12,7 +12,7 @@ - From 970beb2cd679b511e95d8544dce6400f600b757a Mon Sep 17 00:00:00 2001 From: JokeMaker Date: Thu, 16 Dec 2021 11:29:01 +0800 Subject: [PATCH 2/2] Refractor iOS adapter --- .../Plugins/iOS/GoogleSignIn/GoogleSignIn.h | 23 +++++- .../Plugins/iOS/GoogleSignIn/GoogleSignIn.mm | 77 ++++++++++++------- .../GoogleSignIn/GoogleSignInAppController.mm | 35 +-------- 3 files changed, 73 insertions(+), 62 deletions(-) diff --git a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h index 5e77bc10..953e3350 100644 --- a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h +++ b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h @@ -14,7 +14,26 @@ * limitations under the License. */ #import -@interface GoogleSignInHandler - : NSObject +#import + +@interface GoogleSignInHandler : NSObject +{ + @public + GIDConfiguration* signInConfiguration; + + @public + NSString* loginHint; + + @public + NSMutableArray* additionalScopes; +} + +@property(class, nonatomic, readonly) GoogleSignInHandler *sharedInstance; + +- (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController; + +- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)_error; + +- (void)signIn:(GIDSignIn *)signIn didDisconnectWithUser:(GIDGoogleUser *)user withError:(NSError *)_error; @end diff --git a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm index 9b82a370..15822032 100644 --- a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm +++ b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm @@ -18,6 +18,9 @@ #import #import #import +#import + +#import "UnityInterface.h" #import @@ -59,6 +62,19 @@ void UnpauseUnityPlayer() { @implementation GoogleSignInHandler +GIDConfiguration* signInConfiguration = nil; +NSString* loginHint = nil; +NSMutableArray* additionalScopes = nil; + ++ (GoogleSignInHandler *)sharedInstance { + static dispatch_once_t once; + static GoogleSignInHandler *sharedInstance; + dispatch_once(&once, ^{ + sharedInstance = [self alloc]; + }); + return sharedInstance; +} + /** * Overload the presenting of the UI so we can pause the Unity player. */ @@ -105,9 +121,6 @@ - (void)signIn:(GIDSignIn *)signIn case kGIDSignInErrorCodeKeychain: currentResult_->result_code = kStatusCodeInternalError; break; - case kGIDSignInErrorCodeNoSignInHandlersInstalled: - currentResult_->result_code = kStatusCodeDeveloperError; - break; case kGIDSignInErrorCodeHasNoAuthInKeychain: currentResult_->result_code = kStatusCodeError; break; @@ -146,6 +159,7 @@ - (void)signIn:(GIDSignIn *)signIn * The parameters are intended to be primative, easy to marshall. */ extern "C" { + /** * This method does nothing in the iOS implementation. It is here * to make the API uniform between Android and iOS. @@ -168,31 +182,29 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn, bool requestIdToken, bool hidePopups, const char **additionalScopes, int scopeCount, const char *accountName) { - if (webClientId) { - [GIDSignIn sharedInstance].serverClientID = - [NSString stringWithUTF8String:webClientId]; - } - - [GIDSignIn sharedInstance].shouldFetchBasicProfile = true; - - int scopeSize = scopeCount; - - if (scopeSize) { - NSMutableArray *tmpary = - [[NSMutableArray alloc] initWithCapacity:scopeSize]; - for (int i = 0; i < scopeCount; i++) { - [tmpary addObject:[NSString stringWithUTF8String:additionalScopes[i]]]; + NSString *path = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]; + NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; + NSString *clientId = [dict objectForKey:@"CLIENT_ID"]; + GIDConfiguration* config = [[GIDConfiguration alloc] initWithClientID:clientId]; + if (webClientId) { + config = [[GIDConfiguration alloc] initWithClientID:clientId serverClientID:[NSString stringWithUTF8String:webClientId]]; + } + [GoogleSignInHandler sharedInstance]->signInConfiguration = config; + + int scopeSize = scopeCount; + if (scopeSize) { + NSMutableArray *tmpary = [[NSMutableArray alloc] initWithCapacity:scopeSize]; + for (int i = 0; i < scopeCount; i++) { + [tmpary addObject:[NSString stringWithUTF8String:additionalScopes[i]]]; + } + [GoogleSignInHandler sharedInstance]->additionalScopes = tmpary; } - [GIDSignIn sharedInstance].scopes = tmpary; - } - - if (accountName) { - [GIDSignIn sharedInstance].loginHint = - [NSString stringWithUTF8String:accountName]; - } + if (accountName) { + [GoogleSignInHandler sharedInstance]->loginHint = [NSString stringWithUTF8String:accountName]; + } - return !useGameSignIn; + return !useGameSignIn; } /** @@ -226,7 +238,12 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn, void *GoogleSignIn_SignIn() { SignInResult *result = startSignIn(); if (!result) { - [[GIDSignIn sharedInstance] signIn]; + [[GIDSignIn sharedInstance] signInWithConfiguration:[GoogleSignInHandler sharedInstance]->signInConfiguration + presentingViewController:UnityGetGLViewController() + hint:[GoogleSignInHandler sharedInstance]->loginHint + callback:^(GIDGoogleUser *user, NSError *error) { + [[GoogleSignInHandler sharedInstance] signIn:[GIDSignIn sharedInstance] didSignInForUser:user withError:error]; + }]; result = currentResult_.get(); } return result; @@ -239,7 +256,9 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn, void *GoogleSignIn_SignInSilently() { SignInResult *result = startSignIn(); if (!result) { - [[GIDSignIn sharedInstance] signInSilently]; + [[GIDSignIn sharedInstance] restorePreviousSignInWithCallback:^(GIDGoogleUser *user, NSError *error) { + [[GoogleSignInHandler sharedInstance] signIn:[GIDSignIn sharedInstance] didSignInForUser:user withError:error]; + }]; result = currentResult_.get(); } return result; @@ -252,7 +271,9 @@ void GoogleSignIn_Signout() { void GoogleSignIn_Disconnect() { GIDSignIn *signIn = [GIDSignIn sharedInstance]; - [signIn disconnect]; + [signIn disconnectWithCallback:^(NSError *error) { + [[GoogleSignInHandler sharedInstance] signIn:[GIDSignIn sharedInstance] didDisconnectWithUser:nil withError:error]; + }]; } bool GoogleSignIn_Pending(SignInResult *result) { diff --git a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm index 33631489..fe7601c5 100644 --- a/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm +++ b/GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm @@ -62,24 +62,6 @@ + (void)load { - (BOOL)GoogleSignInAppController:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // IMPORTANT: IF you are not supplying a GoogleService-Info.plist in your - // project that contains the client id, you need to set the client id here. - - NSString *path = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" - ofType:@"plist"]; - NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; - NSString *clientId = [dict objectForKey:@"CLIENT_ID"]; - - gsiHandler = [GoogleSignInHandler alloc]; - - // Setup the Sign-In instance. - GIDSignIn *signIn = [GIDSignIn sharedInstance]; - signIn.clientID = clientId; - signIn.uiDelegate = gsiHandler; - signIn.delegate = gsiHandler; - - // looks like it's just calling itself, but the implementations were swapped - // so we're actually calling the original once we're done return [self GoogleSignInAppController:application didFinishLaunchingWithOptions:launchOptions]; } @@ -96,10 +78,7 @@ - (BOOL)GoogleSignInAppController:(UIApplication *)application sourceApplication:sourceApplication annotation:annotation]; - return [[GIDSignIn sharedInstance] handleURL:url - sourceApplication:sourceApplication - annotation:annotation] || - handled; + return [[GIDSignIn sharedInstance] handleURL:url] || handled; } /** @@ -109,16 +88,8 @@ - (BOOL)GoogleSignInAppController:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { - BOOL handled = - [self GoogleSignInAppController:app openURL:url options:options]; - - return [[GIDSignIn sharedInstance] - handleURL:url - sourceApplication: - options[UIApplicationOpenURLOptionsSourceApplicationKey] - annotation: - options[UIApplicationOpenURLOptionsAnnotationKey]] || - handled; + BOOL handled = [self GoogleSignInAppController:app openURL:url options:options]; + return [[GIDSignIn sharedInstance] handleURL:url] || handled; } @end