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

fix for recent Unity iOS and google signin libraries #110

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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ Library/
ProjectSettings/
Temp/
obj/
Logs/
Packages/

# Don't check in the resolver
GoogleSignInPlugin/Assets/PlayServicesResolver/
PlayServicesResolver.meta

# don't checkin client plists
GoogleSignInPlugin/Assets/Plugins/iOS/client*.plist*
GoogleService-Info.plist*

Assembly-CSharp-Editor.csproj
Assembly-CSharp.csproj
Expand All @@ -31,3 +35,6 @@ staging/native/google-signin-cpp
# don't check in iOS pod generated content
contents.xcworkspacedata
staging/native/testapp/testapp.xcodeproj/project.xcworkspace/xcuserdata

# osx
.DS_Store
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.IO;

using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

namespace Google {
public static class UnityEditorPostProessorForSignin {
const string PLIST_FILE_NAME= "GoogleService-Info.plist";
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
{
// Go get pbxproj file
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

// PBXProject class represents a project build settings file,
// here is how to read that in.
PBXProject proj = new PBXProject ();
proj.ReadFromFile (projPath);

// This is the Xcode target in the generated project
string target = proj.TargetGuidByName ("Unity-iPhone");

string[] files = Directory.GetFiles("Assets", PLIST_FILE_NAME, SearchOption.AllDirectories);
if (files.Length > 0) {
// Copy plist from the project folder to the build folder
FileUtil.CopyFileOrDirectory (files[0], Path.Combine(path, PLIST_FILE_NAME));
proj.AddFileToBuild (target, proj.AddFile(PLIST_FILE_NAME, PLIST_FILE_NAME));

// add URLType
var plistPath = Path.Combine(path, "Info.plist");
var plistCred = new PlistDocument();
plistCred.ReadFromFile(files[0]);
var plistInfo = new PlistDocument();
plistInfo.ReadFromFile(plistPath);
var urlentry = plistInfo.root.CreateArray("CFBundleURLTypes")
.AddDict();
urlentry.SetString("CFBundleTypeRole", "Editor");
urlentry.CreateArray("CFBundleURLSchemes").AddString(
plistCred.root["REVERSED_CLIENT_ID"].AsString()
);
plistInfo.WriteToFile(plistPath);

// Write PBXProject object back to the file
proj.WriteToFile (projPath);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions GoogleSignInPlugin/Assets/GoogleSignIn/GoogleSignIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public Task<GoogleSignInUser> SignIn() {
return tcs.Task;
}

public bool SignInCanBeSilent {
get { return impl.SignInCanBeSilent; }
}

/// <summary>Starts the silent authentication process.</summary>
/// <remarks>
/// The authenication process is started and will attempt to sign in without
Expand Down Expand Up @@ -195,6 +199,7 @@ public GoogleSignInStatusCode Status {
internal interface ISignInImpl {
Future<GoogleSignInUser> SignIn();
Future<GoogleSignInUser> SignInSilently();
bool SignInCanBeSilent { get; }
void EnableDebugLogging(bool flag);
void SignOut();
void Disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public Future<GoogleSignInUser> SignIn() {
return new Future<GoogleSignInUser>(new NativeFuture(nativeFuture));
}

public bool SignInCanBeSilent {
get {
return GoogleSignIn_CanBeSilent(SelfPtr());
}
}

/// <summary>
/// Starts the authentication process.
/// </summary>
Expand Down Expand Up @@ -133,6 +139,9 @@ static extern bool GoogleSignIn_Configure(HandleRef self,
[DllImport(DllName)]
internal static extern bool GoogleSignIn_Pending(HandleRef self);

[DllImport(DllName)]
internal static extern bool GoogleSignIn_CanBeSilent(HandleRef self);

[DllImport(DllName)]
internal static extern IntPtr GoogleSignIn_Result(HandleRef self);

Expand Down
Binary file not shown.
36 changes: 0 additions & 36 deletions GoogleSignInPlugin/Assets/Parse/Plugins/Unity.Tasks.dll.meta

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/
#import <GoogleSignIn/GIDSignIn.h>
@interface GoogleSignInHandler
: NSObject <GIDSignInDelegate, GIDSignInUIDelegate>
: NSObject <GIDSignInDelegate, GIDSignInDelegate>

@end
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,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 @@ -232,14 +229,18 @@ bool GoogleSignIn_Configure(void *unused, bool useGameSignIn,
return result;
}

bool GoogleSignIn_CanBeSilent() {
return [GIDSignIn sharedInstance].hasPreviousSignIn;
}

/**
* Attempt a silent sign-in. Return value is the pointer to the currentResult
* object.
*/
void *GoogleSignIn_SignInSilently() {
SignInResult *result = startSignIn();
if (!result) {
[[GIDSignIn sharedInstance] signInSilently];
[[GIDSignIn sharedInstance] restorePreviousSignIn];
result = currentResult_.get();
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ + (void)load {
Method swizzled;

original = class_getInstanceMethod(
self, @selector(application:didFinishLaunchingWithOptions:));
self, @selector(preStartUnity));
swizzled = class_getInstanceMethod(
self,
@selector(GoogleSignInAppController:didFinishLaunchingWithOptions:));
@selector(GoogleSignInAppController_preStartUnity));
method_exchangeImplementations(original, swizzled);

original = class_getInstanceMethod(
Expand All @@ -59,8 +59,7 @@ + (void)load {
method_exchangeImplementations(original, swizzled);
}

- (BOOL)GoogleSignInAppController:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- (void)GoogleSignInAppController_preStartUnity {

// 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.
Expand All @@ -75,13 +74,12 @@ - (BOOL)GoogleSignInAppController:(UIApplication *)application
// Setup the Sign-In instance.
GIDSignIn *signIn = [GIDSignIn sharedInstance];
signIn.clientID = clientId;
signIn.uiDelegate = gsiHandler;
signIn.delegate = gsiHandler;
signIn.presentingViewController = UnityGetGLViewController();

// 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];
[self GoogleSignInAppController_preStartUnity];
}

/**
Expand All @@ -96,10 +94,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 @@ -112,13 +107,7 @@ - (BOOL)GoogleSignInAppController:(UIApplication *)app
BOOL handled =
[self GoogleSignInAppController:app openURL:url options:options];

return [[GIDSignIn sharedInstance]
handleURL:url
sourceApplication:
options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:
options[UIApplicationOpenURLOptionsAnnotationKey]] ||
handled;
return [[GIDSignIn sharedInstance] handleURL:url] || handled;
}

@end