Search code examples
iosintellij-idealibgdxrobovm

Gdx-pay crashes when attempting a purchase on iOS


I am attempting to use gdx-pay to add IAP to my app. This is working fine on Android but my app crashes when attempting a test purchase. I have successfully setup the Sandbox on iTunes Connect, it seems the purchase manager is at least connecting succesfully. I however do not get any stack trace on the app crash so I don't really know how to start debugging this. I have added logs in as many places as possible, constrained by some read-only files. This is how the flow goes when I try to purchase an IAP:

[GdxPay/AppleIOS] Products successfully received!
[GdxPay/AppleIOS] Purchase observer successfully installed!
2017-02-06 18:27:01.475036 Snowfall[478:80137] [info] PAYMENTINFO: Handling Install
[GdxPay/AppleIOS] There are 0 unfinished transactions. Try to finish...
[GdxPay/AppleIOS] Products successfully received!
[GdxPay/AppleIOS] Purchase observer successfully installed!
2017-02-06 18:27:01.719032 Snowfall[478:80137] [info] PAYMENTINFO: Handling Install
[GdxPay/AppleIOS] There are 0 unfinished transactions. Try to finish...
2017-02-06 18:28:02.054620 Snowfall[478:80137] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2017-02-06 18:28:02.054790 Snowfall[478:80137] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
[GdxPay/AppleIOS] Purchasing product char2 ...

Process finished with exit code -1

Not too sure why the 'process finishes' , the app closes and there is no stack trace. I am using IntelliJ on Mac OS. A simple starter question is how do I enable a better stack trace on IntelliJ? And slightly more complicated, what is going on here?

LibGDX version 1.9.5

roboVM version 2.3.0

gdx-pay version 0.10.3

Here is the relevant iOS code. All of the other gdx-pay code is mostly copy-paste from Github and works fine with Android.

Launch:

public class Snowfall extends IOSApplication.Delegate {
JumpV6 game;
@Override
protected IOSApplication createApplication() {
    IOSApplicationConfiguration config = new IOSApplicationConfiguration();
    config.orientationLandscape = true;
    config.orientationPortrait = false;
    game = new JumpV6();
    game.setAppStore(APPSTORE_APPLE);
    return new IOSApplication(game, config);
}

@Override
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
    super.didFinishLaunching(application, launchOptions);
    game.setPlatformResolver(new IOSResolver(game));
    return true;
}


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

Resolver:

public class IOSResolver extends PlatformResolver {

String appleKey = "......"; //omitted

public IOSResolver(JumpV6 myGame) {
    super();

    PurchaseManagerConfig config = myGame.purchaseManagerConfig;
    config.addStoreParam(PurchaseManagerConfig.STORE_NAME_IOS_APPLE,appleKey);
    initializeIAP(null, myGame.purchaseObserver, config);
    installIAP();
}}

Thank you


Solution

  • After a while of working through this, it seems all I needed to do was post on Stack in order to see what I was doing wrong. The Resolver class was copy-pasted from the internet somewhere, and I realized I never actually went through what each line was doing. I then thought that installIAP() did not need to be there so I commented it out. Working Resolver:

    public class IOSResolver extends PlatformResolver {
        String appleKey = "......"; //omitted
        public IOSResolver(JumpV6 myGame) {
            super();
            PurchaseManagerConfig config = myGame.purchaseManagerConfig;
            config.addStoreParam(PurchaseManagerConfig.STORE_NAME_IOS_APPLE,appleKey);
            initializeIAP(null, myGame.purchaseObserver, config);
            //installIAP();
        }
    }