如何用IAP以不同国家的货币显示价格

时间:2015-07-01 14:28:35

标签: ios swift in-app-purchase storekit

这意味着当人们要在我的游戏中购买东西时,我应该在他们点击"购买"之前先向他们展示对象的价格。按钮,但在不同的国家,我们需要使用不同的货币,如果用户在美国,他应该看到价格是0.99美元,而在另一个国家我应该用价格显示他们的本地货币,所以我怎么能在代码中在我的项目中。  我很抱歉,但我是IOS的新手,所以非常希望得到你的帮助,非常感谢你

2 个答案:

答案 0 :(得分:2)

从Apple获得产品后,您可以从price - https://developer.apple.com/library/ios/documentation/StoreKit/Reference/SKProduct_Reference/#//apple_ref/occ/instp/SKProduct/price获取当地货币的SKProduct - 然后您可以在购买界面中向用户显示

更多详细信息(包括带格式的代码示例):http://bendodson.com/weblog/2014/12/10/skproduct-localized-price-in-swift/

答案 1 :(得分:1)

以下是满足您需求的Objective C解决方案 - 您可以include Objective C Header into your swift project并使用它。

- (NSString *) getLocalizedCurrencyString : (NSNumber *) amount :(NSLocale *)priceLocale
{
    NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
    [currencyFormatter setLocale:priceLocale];
    [currencyFormatter setMaximumFractionDigits:2];
    [currencyFormatter setMinimumFractionDigits:2];
    [currencyFormatter setAlwaysShowsDecimalSeparator:YES];
    [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];

    NSString *localizedCurrency = [currencyFormatter stringFromNumber:amount];
    return localizedCurrency;
}

<强>用法:

let priceLocale: NSLocale = product.priceLocale as NSLocale
let price: NSString = IAPHelper.sharedInstance().getLocalizedCurrencyString(product.price, priceLocale)

其中IAPHelper是持有IAP代码的Objective C类。

相关问题