Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get In-App-Item Price In USD - Instead of User's Local Coin

For Analysis and collecting data I want to get The price of SKProduct in dollars.

The base code I use to show the user the price is :

   _priceFormatter = [[NSNumberFormatter alloc] init];
   [_priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
   [_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];

   [_priceFormatter setLocale:inAppProduct.priceLocale];
   inAppItemString = [_priceFormatter stringFromNumber:inAppProduct.price];

This code give me the real price the user should pay with his local coin

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

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

Any idea how to get the price in USD ?

like image 326
Yossi Avatar asked Jun 02 '14 08:06

Yossi


1 Answers

You can send an http get request to an online conversion service, e.g.:

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

returning

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

to get the rate, which hopefully should not be too far from the rate used by Apple, and then calculate the value in USD.

like image 77
Bjørn Egil Avatar answered Nov 12 '22 08:11

Bjørn Egil