Get the price for the entry position in US dollars - instead of the user's local coin

For analysis and data collection, I want to get the SKProduct price in dollars.

The basic code that I use to show the user the price:

_priceFormatter = [[NSNumberFormatter alloc] init]; [_priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; [_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [_priceFormatter setLocale:inAppProduct.priceLocale]; inAppItemString = [_priceFormatter stringFromNumber:inAppProduct.price]; 

This code gives me the real price that the user must pay with his local coin.

I tried setting local as en_US, but I got the same price as before, with $ :) This is what I changed for this:

  NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; [_priceFormatter setLocale:usLocale]; 

Any idea how to get the price in US dollars?

+6
source share
2 answers

You can try the following:

 NSLocale *priceLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; 

Link: Is there an easy way to format a currency into a string in iOS?

0
source

You can send an http request to an online conversion service, for example:

 http://api.fixer.io/latest?base=GBP&symbols=USD 

return

 {"base":"GBP","date":"2016-09-01","rates":{"USD":1.3261}} 

to get a bet that I hope should not be too far from the speed used by Apple, and then calculate the value in US dollars.

0
source

Source: https://habr.com/ru/post/970164/


All Articles