I am currently working on porting my LibGDX game to iOS using roboVM. Everything works except I have run into some issues with getting my bindings to work for admob and Google Play Game Services. I was able to workaround an issue with Admob but the same issue has come up for GPGS and I can't find a way around it. The bindings are hooks that tie into various iOS SDK's. I use them to show Admob ads and interface with Google Play services.
I tried to follow the Sample.java here:
Sample.java
But it has some issues for me. First of all the didFinishLaunching() method the sample overrides is wrong and never gets called. It should override didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) instead.
The main issue I'm having now is that the game does not accept user inputs due to the window.makeKeyAndVisible() call. If I take that method out, everything works great but I cannot show ads nor show the Google Play Services. I will see a warning about the window not being in the view hierarchy. I was able to work around this for the admob interstitial ads by only calling makeKeyAndVisible() before showing the ad and calling setHidden() after it is dismissed in the interstitial's delegate. However I do not have access to do the same with Google Play services. It doesn't seem like anyone else is encountering this issue. What could be the problem? I'm not very familiar with iOS so I don't get what needs to happen to make my app receive inputs properly.
Okay so releasing a LibGDX game to iOS with Admob and GPGS or other bindings is a painful process, but I have managed to get everything working and my game is now in the waiting for review state. At the time of this answer it looks like Apple is rejecting apps that use Google Play Game Services because the GPGS SDK takes the user to Safari in order to log in. This is unacceptable per Apple because it is a "poor user experience". Actually when a user tries to log in the GPGS SDK looks for an installation of Google+ in order to log in, if it can't be found it then it opens a Chrome browser, and finally Safari if Chrome isn't installed. After getting the GPGS correctly integrated and trying to submit my binary to Apple I was facing another issue about the Google SDK not being signed. Since it looked like my app would be rejected even if I were to fix that issue I decided to ditch GPGS and use Apple's Game Center instead. That said, I was still able to get GPGS with Admob working on my test device so I can answer how here.
First, the samples in BlueRiverInteractive are not all that useful for a LibGDX game. All the UIWindow, UIViewController and UIView stuff you shouldn't have to mess with. Your IOSLauncher class should extend Delegate instead of UIApplicationDelegateAdapter. If you look inside Delegate, it takes care of setting UIApplication, UIWindow, and other iOS things for your application. When you extend it, you will be forced to implement createApplication(). This is mine for example:
@Override
protected IOSApplication createApplication() {
final IOSApplicationConfiguration config = new IOSApplicationConfiguration();
config.orientationLandscape = false;
config.orientationPortrait = true;
config.useAccelerometer = false;
config.useCompass = false;
iosApplication = new IOSApplication(new SplishGame(this), config);
return iosApplication;
}
Keep iosApplication as a field member of your IOSLauncher class. Through it, you can get the UIWindow that you need to show interstitials and the Leaderboards / Achievements.
Second thing to do is make sure your IOSLauncher class is overriding didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) instead of the didFinishLaunching method with only one parameter or else it won't get called. In your didFinishLaunching method, you can instantiate your GPGS manager class (more on that in a second) and try to login silently. Which reminds of of another issue I ran into while trying to integrate GPGS - make sure you're using the GPGS manager object to make life easier (PlayServicesManager). There are two Samples in the GPGS bindings project and I was initially looking at the 'hard to use' one which doesn't using the PlayServicesManager class. Once you have your manager object set up you can call simple methods like manager.login() or manager.getLeaderboards() to do what you need to do.
To initialize your manager class in the didFinishLaunching method do this:
playManager = new PlayServicesManager();
playManager.setClientId(CLIENT_ID);
playManager.setUserDataToRetrieve(true, false);
playManager.setViewController(iosApplication.getUIViewController());
playManager.didFinishLaunching();
For Game Center it's like this:
gcManager = new GameCenterManager(iosApplication.getUIWindow(), new GameCenterListener() {...(overridden methods left blank)
gcManager.login();
Then the code form your core project can call the necessary functions through your ActionResolver interface - or whatever you named your native interface. So you'd have stuff like:
@Override
public void getLeaderboards() {
log.debug("Showing all leaderboards.");
playManager.showLeaderboardsPicker();
}
And everything should work.
One more thing that apparently you need to do (only for GPGS) is copy this method into your IOSLauncher class:
// copy-paste this to your app delegate.
@Override
public boolean openURL(UIApplication application, NSURL url, String sourceApplication, NSPropertyList annotation) {
return GPPURLHandler.handleURL(url, sourceApplication, annotation);
}
So that's about it as far as I can recall. Please post if you think something is wrong or I forgot something important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With