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 scre开发者_如何学运维en 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?
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.
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];
精彩评论