robovm / robovm-robopods

63 stars 86 forks source link

Libgdx - Unable to sign in using Web view with Robopods Google Sign In. #116

Open Jay3shh opened 8 years ago

Jay3shh commented 8 years ago

I'm using LibGDX & Eclipse set-up. I've managed to successfully sign in using robopods 1.14.0, however this method happens via a Safari Web browser and not the Web View which makes it pointless.

I've made several attempts to resolve this and have referred to various other posts, nothing seems to be working so far.

In my IOS Launcher class, I have :

public class IOSLauncher extends IOSApplication.Delegate {

    private GADBannerView bannerView;
    private ViewController viewController;

    @Override
    protected IOSApplication createApplication() {
        IOSApplicationConfiguration config = new IOSApplicationConfiguration();
        return new IOSApplication(new example(new ViewController()), config);
    }

    public static void main(String[] argv) {
        NSAutoreleasePool pool = new NSAutoreleasePool();
        UIApplication.main(argv, null, IOSLauncher.class);
        pool.close();
    }

    @Override
    public boolean didFinishLaunching(UIApplication application,
                                      UIApplicationLaunchOptions launchOptions) {
        // TODO Auto-generated method stub
        boolean b = super.didFinishLaunching(application, launchOptions);
        Foundation.log("IOSLauncher didFinishLaunching()");

        try {

        viewController = new ViewController();
        GIDSignIn.getSharedInstance().setAllowsSignInWithWebView(true);

        viewController.signIn();

        } catch (Exception e) {
            Foundation.log("Error configuring the Google context: " + e);
        }

        return b;
    }

    @Override
    public boolean openURL(UIApplication application, NSURL url, String sourceApplication, NSPropertyList annotation) {
        return GIDSignIn.getSharedInstance().handleURL(url, sourceApplication, annotation);
    }
}

In my ViewController class, I have :

public ViewController() {

        GPGManager.getSharedInstance().setStatusDelegate(new GPGStatusDelegateAdapter() {
            @Override
            public void didFinishGamesSignIn(NSError error) {
                Foundation.log("didFinishGamesSignIn(" + error + ")");
            }

            @Override
            public void didFinishGamesSignOut(NSError error) {
                Foundation.log("didFinishGamesSignOut(" + error + ")");
            }

            @Override
            public void didFinishGoogleAuth(NSError error) {
                Foundation.log("didFinishGoogleAuth(" + error + ")");
            }

            @Override
            public boolean shouldReauthenticate(NSError error) {
                Foundation.log("shouldReauthenticate(" + error + ")");
                return false;
            }

            @Override
            public void willReauthenticate(NSError error) {
                Foundation.log("willReauthenticate(" + error + ")");
            }

            @Override
            public void didDisconnect(NSError error) {
                Foundation.log("didDisconnect(" + error + ")");
            }
        });

        GIDSignIn.getSharedInstance().setAllowsSignInWithWebView(true);

        GIDSignIn.getSharedInstance().setUiDelegate(new GIDSignInUIDelegateAdapter() {

            @Override
            public void willDispatch(GIDSignIn signIn, NSError error) {
                Foundation.log("willDispatch()");
            }

            @Override
            public void presentViewController(GIDSignIn signIn, UIViewController viewController) {
                Foundation.log("presentViewController()");

                UIApplication.getSharedApplication().getKeyWindow().getRootViewController()
                        .presentViewController(viewController, true, null);

            }

            @Override
            public void dismissViewController(GIDSignIn signIn, UIViewController viewController) {
                Foundation.log("dismissViewController()");
                viewController.dismissViewController(true, null);
            }
        });

    }

My info file has:


    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>com.example.game</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.example.game</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>com.googleusercontent.apps.175333595465-123456789</string> 
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.example.game</string>
                <string>com.googleusercontent.apps.123456789</string>
            </array>
        </dict>
    </array>

This is what my Robovm.xml looks like :


<frameworks>
    <framework>UIKit</framework>s
    <framework>OpenGLES</framework>
    <framework>QuartzCore</framework>
    <framework>CoreGraphics</framework>
    <framework>OpenAL</framework>
    <framework>AudioToolbox</framework>
    <framework>AVFoundation</framework>
    <framework>SafariServices</framework>
    <framework>WebKit</framework>
     <framework>GoogleOpenSource</framework>
      <framework>GoogleMobileAds</framework>
<framework>GooglePlus</framework>

<framework>GoogleSignIn</framework>
<framework>gpg</framework>

  </frameworks>

Finally, to sign in I call:

GPGManager.getSharedInstance().signIn(CLIENT_ID, false);

I've also got the GoogleService-info.plist Configuration file set-up in my resources folder.

I'm using the latest Google Sign in SDK that is 3_0_0 and i'm using google plus iOS SDK 1.7.1

As stated earlier, everything works fine as I'm able to sign in, but happens via Safari Web Browser instead of the WebView which makes it useless as then my app wouldn't get approved by Apple. Am i missing anything?

DavidBVal commented 8 years ago

Hello, I have exactly the same problem (everything works fine, but sign-in is done through Safari). did you manage to solve the problem?