Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Release HERE!!!] Update native sdk version to 6.0.2 & REFECTOR iOS Adapter #205

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- See https://github.com/googlesamples/unity-jar-resolver#usage for
how to configure dependencies -->
<androidPackages>
<androidPackage spec="com.google.android.gms:play-services-auth:16+">
<androidPackage spec="com.google.android.gms:play-services-auth:20+">
<androidSdkPackageIds>
<androidSdkPackageId>extra-google-m2repository</androidSdkPackageId>
</androidSdkPackageIds>
Expand All @@ -12,7 +12,7 @@

<!-- iOS Cocoapod dependencies can be specified by each iosPod element. -->
<iosPods>
<iosPod name="GoogleSignIn" version=">= 4.0.2" bitcodeEnabled="false"
<iosPod name="GoogleSignIn" version=">= 6.0.2" bitcodeEnabled="false"
minTargetSdk="6.0">
</iosPod>
</iosPods>
Expand Down
23 changes: 21 additions & 2 deletions GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,26 @@
* limitations under the License.
*/
#import <GoogleSignIn/GIDSignIn.h>
@interface GoogleSignInHandler
: NSObject <GIDSignInDelegate, GIDSignInUIDelegate>
#import <GoogleSignIn/GIDConfiguration.h>

@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
77 changes: 49 additions & 28 deletions GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#import <GoogleSignIn/GIDGoogleUser.h>
#import <GoogleSignIn/GIDProfileData.h>
#import <GoogleSignIn/GIDSignIn.h>
#import <UnityAppController.h>

#import "UnityInterface.h"

#import <memory>

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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;
}

/**
Expand All @@ -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