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

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

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

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

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

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

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

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

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

解决方法

您可能想尝试以下方法
NSLocale *priceLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];

参考:Is there a simple way to format currency into string in iOS?

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...