jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
651 stars 152 forks source link

ArgumentNullException in iOS LocalizedPrice(this SKProductDiscount product) #148

Closed mavaa closed 6 years ago

mavaa commented 6 years ago

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin: 1.2.5 Device Tested On: iPhone 6, iOS 11.3.1 Simulator Tested On: None Version of VS: 15.6.7 Version of Xamarin: 4.9.0.753 Versions of other things you are using:

Steps to reproduce the Behavior

Expected Behavior

Actual Behavior

I'm not sure if I've set something up wrong, or if this is a bug on the Xamarin or iOS side of things, but I've managed to do a workaround by changing the LocalizedPrice extension method to: public static string LocalizedPrice(this SKProductDiscount product, NSLocale locale)

And the call on GetProductInfoAsync to: LocalizedIntroductoryPrice = IsiOS112 ? (p.IntroductoryPrice?.LocalizedPrice(p.IntroductoryPrice?.PriceLocale ?? p.PriceLocale) ?? string.Empty) : string.Empty,

I can make a PR tomorrow is this is an acceptable fix, just wanted to check if anyone knows anything more about this issue than I can find out right now.

Code snippet

IInAppBilling billing = CrossInAppBilling.Current;

try
{
    bool connected = await billing.ConnectAsync();

    if (connected)
    {
        // Gets product id's from our server (only a single one in the test case)
        List<string> productIDs = this.GetProductIDs();

        // Exception happens here, when ToList triggers the Linq Select call in GetProductInfoAsync
        var subscriptions = (await billing.GetProductInfoAsync(ItemType.Subscription, productIDs.ToArray())).ToList();

        return subscriptions;
    }
}
catch (Exception ex)
{
    this.logger.LogError(ex);
}
finally
{
    await billing.DisconnectAsync();
}

return null;

Screenshots

Downloaded the project and stopped where the InAppBillingProduct(s) are created

2018_05_02_15_51_40

mavaa commented 6 years ago

Thanks, I think I prefer my solution of falling back to SKProduct.PriceLocale if the other one is null as I can't see any scenario where they wouldn't be the same anyways. Do you want me to submit a PR for it, or do you prefer the version of returning string.empty?

jamesmontemagno commented 6 years ago

Already implemented and released in the pre-release :)