在应用程序购买本地货币符号中更正

pet*_*ete 3 currency in-app-purchase ios nslocale

在应用程序购买中,我希望本地货币符号显然适合用户本地货币.使用NSLocaleCurrencySymbol作为检测用户所在位置的主要来源是否安全.这是我的代码的一部分:

         NSLocale *theLocale = [NSLocale currentLocale];
     NSString *symbol = [theLocale objectForKey:NSLocaleCurrencySymbol];
     NSString *cost = [NSString stringWithFormat:@"%@",product.price];
Run Code Online (Sandbox Code Playgroud)

默认情况下,当用户购买iOS设备时,在每台设备的国际设置中自动完成正确的区域格式?

Ric*_*ich 9

你想用一个NSNumberFormatter:

Objective-C的

NSNumberFormatter *formatter = [NSNumberFormatter new];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setLocale:product.priceLocale]; 
NSString *cost = [formatter stringFromNumber:product.price];
Run Code Online (Sandbox Code Playgroud)

迅速

let formatter = NSNumberFormatter()
formatter.numberStyle = .CurrencyStyle
formatter.locale = product.priceLocale
let cost = formatter.stringFromNumber(product.price)
Run Code Online (Sandbox Code Playgroud)

然后,这将使用正确的十进制,分隔符和货币符号格式化货币.

  • 在其他商店中创建测试帐户(您可以在打开测试帐户时设置国家/地区).这样你就可以看出货币是否正常. (2认同)