I'm putting links to other apps by the same company into an iPhone app, and we want to display the price of those apps. Is it possible to somehow get the localized price string (amount and currency) that's appropriate for the user? I imagine I'd have to resort to something like screen scraping, but I've seen that people can get quite a lot of information out of App Store so maybe there's some relatively simple way?
+4
A:
There's an iTunes Web Service API you can use.
http://www.apple.com/itunesaffiliates/API/AffiliatesSearch2.1.pdf documents it.
You can use the 'country' query field to specify which country you wish results returned by.
You can get the user's country name using NSLocale
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *countryName = [locale displayNameForKey: NSLocaleCountryCode
value: countryCode]];
though you may need a lookup table to format this in the same way the iTunes store API does.
NeilInglis
2010-03-05 14:14:52
Wow, definitely a lot easier than I had thought. Thanks!
Felixyz
2010-03-05 15:07:11
A:
If you can extract the price as a simple number, NSNumberFormatter will provide you currency localization.
NSDecimalNumber *price = [NSDecimalNumber decimalNumberWithString:@"4.95"];
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
This will add the currency from the users default regiona settings. If you want to change regional settings, use:
[currencyFormatter setLocale:anyLocale];
Enyra
2010-03-05 14:59:45
Very interesting, although it's not enough in this situation. So the system retains information about recent exchange rates, which NSNumberFormatter uses?
Felixyz
2010-03-05 15:08:22
Actually, I think all that code does is add the relevant currency symbol for the user's region.
NeilInglis
2010-03-05 15:14:16
@FelixyzThis has nothing to do with exchange rate calculation, it just formats your number value with the regional currency settings.
Enyra
2010-03-05 15:33:10