libgdx / gdx-pay

A libGDX cross-platform API for InApp purchasing.
Apache License 2.0
224 stars 83 forks source link

PurchaseSystem.getInformation crashes on iOS 9 #157

Closed lozan closed 7 years ago

lozan commented 7 years ago

Calling PurchaseSystem.getInformation(String identifier) crashes the app on iOS 9. It works on iOS 10 and 11.

The issue seems to be in "gdx-pay-iosmoe-apple/src/main/java/com/badlogic/gdx/pay/ios/apple/PurchaseManageriOSApple.java" in the function "public Information getInformation(String identifier)".

Based on the exception, I assume the call that makes it crash is the following: p.priceLocale().currencyCode()

Here's the exception:

[GdxPay/AppleIOS] Purchase observer successfully installed!
-[__NSCFLocale currencyCode]: unrecognized selector sent to instance 0x1c96b100
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFLocale currencyCode]: unrecognized selector sent to instance 0x1c96b100'
*** First throw call stack:
(0x25015b0b 0x247d2dff 0x2501b455 0x250190ab 0x24f43298 0x3e5001c 0x3e522d5 0x3e4b33b 0x3e4b26b 0x3e489db 0x3e52619 0x3e500a4)
libc++abi.dylib: terminating with uncaught exception of type NSException
Tom-Ski commented 7 years ago

That method is not available on iOS 9, so you can't use it.

lozan commented 7 years ago

Right, but it's in gdx-pay. Or you mean I can't use PurchaseSystem.getInformation() ? Isn't there a way to get info about a product on iOS 9 through gdx-pay?

Tom-Ski commented 7 years ago

I don't use the library, but if thats the case then it should be declared not compatible with < iOS 10, or it should not use that API internally.

keesvandieren commented 7 years ago

The iosmoe implementation is based on the robovm implementation. org.robovm.apple.foundation.NSLocale#getCurrencySymbol implementation:

public String getCurrencySymbol() {
    if (Foundation.getMajorSystemVersion() >= 10) {
        return getCurrencySymbol0();
    } else {
        NSString val = (NSString)getComponent(NSLocaleComponent.CurrencySymbol);
        return val.toString();
    }
}

So on Robovm this doesn't crash, only on MOE.

We should probably use apple.foundation.NSLocale#objectForKey. with key "CurrencyCode".

Robovm has listed the keys in org.robovm.apple.foundation.NSLocaleComponent. Has MOE something similar @liliomk?

lozan commented 7 years ago

There's something in: https://github.com/multi-os-engine/moe-core/blob/master/moe.apple/moe.platform.ios/src/main/java/apple/foundation/NSLocale.java public native String currencyCode();

I'm not sure if that's what's needed here though

keesvandieren commented 7 years ago

I have fixed that particular call and published a SNAPSHOT to https://oss.sonatype.org/content/repositories/snapshots/

Can you give it a try in iOS 9?

Works only with Xcode 8 (moe doesn't support Xcode 9 yet, that's why I cannot test this anymore)

lozan commented 7 years ago

It works. Awesome! I tested this on the following iOS versions, and it's all good:

9.3.4 (iPhone) 9.3.5 (iPad) 10.3.3 (iPhone) 11.0 (iPad)

keesvandieren commented 7 years ago

Thanks for testing! Released 0.11.2 which has this fix.