BoomShaka
BoomShaka

Reputation: 1801

Get ios app store price in correct currency for price tier and location

Let's say I have a huge catalog of products setup for in app purchase, at various price tiers. The products will be for sale in multiple territories, and hence require the price to be displayed in the correct currency.

Is there a way I can request (from itunes) the monetary value for a given price tier in a given country (the users itunes account country of course)?

At present the only way I can see to do this is to send a product info request to apple for the first occurrence of a product for a given price tier and then store this result.

As a side question: I know I could use my server to return the price for a currency/tier combo, but I'm concerned about the possibility that Apple tweaks in-app prices. Is there any chance that could happen?

Upvotes: 4

Views: 4794

Answers (2)

mxcl
mxcl

Reputation: 26893

extension SKProduct {
    var localizedPriceString: String? {
        let formatter = NumberFormatter()
        formatter.formatterBehavior = .behavior10_4
        formatter.numberStyle = .currency
        formatter.locale = priceLocale
        return formatter.string(from: price)
    }
}

Upvotes: 2

Hyperbole
Hyperbole

Reputation: 3947

Check the docs for SKProduct's handling of the price property, there's sample code there that will do it for you.


Code from the link that wasn't stale after five years: (lightly adapted for Swift 3.0 and style):

Swift 3.0

    let numberFormatter = NumberFormatter()

    numberFormatter.formatterBehavior = .behavior10_4
    numberFormatter.numberStyle = .currency
    numberFormatter.locale = someProduct.priceLocale

    let formattedString = numberFormatter.string(from: someProduct.price)

Objective C

    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];

    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [numberFormatter setLocale:product.priceLocale];

    NSString *formattedString = [numberFormatter stringFromNumber:product.price];

One final thing: NumberFormatter objects are expensive (in terms of time and resources), so considering caching one somewhere if you're expecting to use it often.

Upvotes: 1

Related Questions