以美元获取应用内商品价格 - 而不是用户的本地硬币

Yos*_*ssi 8 localization in-app-purchase ios skproduct

对于分析和收集数据,我想以美元的价格获得SKProduct的价格.

我用来向用户显示价格的基本代码是:

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

   [_priceFormatter setLocale:inAppProduct.priceLocale];
   inAppItemString = [_priceFormatter stringFromNumber:inAppProduct.price];
Run Code Online (Sandbox Code Playgroud)

此代码为我提供了用户应使用当地硬币支付的实际价格

我尝试将本地设置为en_US,但是我得到了与以前相同的价格,以及$ :)这是我改变尝试这个:

   NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
   [_priceFormatter setLocale:usLocale];
Run Code Online (Sandbox Code Playgroud)

知道如何以美元获得价格吗?

小智 0

您可能想尝试以下操作:

NSLocale *priceLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
Run Code Online (Sandbox Code Playgroud)

参考:iOS中有没有简单的方法将货币格式化为字符串?