Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentNullException in iOS LocalizedPrice(this SKProductDiscount product) #148

Closed
mavaa opened this issue May 2, 2018 · 2 comments
Closed

Comments

@mavaa
Copy link

mavaa commented May 2, 2018

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

  • Create an Auto renewing subscription with introductory price. Only localized to english, but prices set for all available contries
  • Testing with a norwegian sandbox account, with english UI on the phone, not sure if this is relevant (prices show up as NOK, but all text and UI localization is in english).
  • Run GetProductInfoAsync with the created product id

Expected Behavior

  • Get a list of products

Actual Behavior

  • I get an ArgumentNullException, because apparently SKProduct.IntroductoryPrice.PriceLocale is null, while SKProduct.PriceLocale is not. Happens in
    public static string LocalizedPrice(this SKProductDiscount product) src\Plugin.InAppBilling.iOS\InAppBillingImplementation.cs, line 548

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
Copy link
Author

mavaa commented May 3, 2018

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
Copy link
Owner

Already implemented and released in the pre-release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants