如何在iOS中获取应用内购买的区域设置货币价格?

Sen*_*mar 27 iphone objective-c in-app-purchase ios

我想找出用户的App Store位置.这意味着他们在美国,澳大利亚(澳大利亚)商店.以下代码使用.

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    Books = response.products;
    if ([SKPaymentQueue canMakePayments] && [response.products count]>0) {

    }

    for (SKProduct *book in Books) {
        NSLocale *locat=[NSLocale currentLocale];
        NSString *strlocate=[locat objectForKey:NSLocaleCountryCode];

        NSLog(@"\n\n\n Device country== %@ \n\n\n",strlocate);

        NSLocale* storeLocale = book.priceLocale;
        NSString *storeCountry = (NSString*)CFLocaleGetValue((CFLocaleRef)storeLocale, kCFLocaleCountryCode);
        NSLog(@"\n\n\n store country== %@ \n\n\n",storeCountry);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要明智的是,如果图书等级是一个意味着US $ 0.99 AUD 0.99 JPY 85,基于应用商店价格矩阵表.

我在模拟器中测试过.我在系统中的iTunes,appstore和safari应用程序中更改了国家/地区名称.但我只得到美国国家代码.

编辑:设置 - >常规 - >国际 - >区域格式 - >国家/地区

我在设备中测试过:设备国家/地区仅更改.商店国家显示美国国家代码和价格.我想在开始购买时间之前存储国家/地区代码.

一旦基于货币波动改变价格多少天?是否为已知/更新提供任何api /查询波动的价格?

我的inapp操作成了一堂课.在inapp操作之前,我想向用户显示本地价格,在inapp操作中反映相同的价格效果.

我显示从我的服务器获取的书籍免费和付费书籍列表.因为我显示每个项目的价格.那些项目价格在处理appstore时会显示美元价格.如果appstore显示价格,我也想显示.所以我想从我的服务器发送国家代码到我的服务器响应该国家相关的价格表和货币符号..

And*_*lva 31

productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:prodcutIdentifier];
    productsRequest.delegate = self;
    
    // This will trigger the SKProductsRequestDelegate callbacks
    [productsRequest start];
Run Code Online (Sandbox Code Playgroud)

这将调用您的委托功能.完成上述操作后,它将最终自动调用下面提到的函数.这是发送的应用商店请求最终确定的位置.

(void)requestDidFinish:(SKRequest *)request
{
   
    
    SKProduct *book = [Books objectAtIndex:0];
        
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [numberFormatter setLocale:book.priceLocale];
    
    NSLocale* storeLocale = book.priceLocale;
    NSString *storeCountry = (NSString*)CFLocaleGetValue((CFLocaleRef)storeLocale, kCFLocaleCountryCode);
    
}
Run Code Online (Sandbox Code Playgroud)

根据您的兴趣提供区域设置和国家/地区详细信息.

  • 你在这个例子中何时使用numberFormatter ......? (4认同)

Asi*_*eba 28

这本书是SKProduct:

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:book.priceLocale];
NSString *formattedPrice = [numberFormatter stringFromNumber:book.price];

NSLog(@"%@", formattedPrice);
Run Code Online (Sandbox Code Playgroud)

简单地问一下有什么不清楚!

问候,

  • 我想在开始inapp购买之前..显示当地价格 (2认同)

msk*_*skw 10

一行代码:

productSKProduct对象实例:

NSString *price = [NSString stringWithFormat:@"%@%@ %@", [product.priceLocale objectForKey:NSLocaleCurrencySymbol], product.price, [product.priceLocale objectForKey:NSLocaleCurrencyCode]];
Run Code Online (Sandbox Code Playgroud)

结果:

1.39美元

  • 投了反对票。此标签对于美元和其他一些货币是正确的,但对于卢布来说是不正确的:“1.39 р.”。您应该始终使用“NumberFormatter” (2认同)

Nik*_*a P 6

我用这个:

  NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [numberFormatter setLocale:basicProduct.priceLocale];
    NSString *formattedString = [numberFormatter stringFromNumber:basicProduct.price];
    NSLog(@"product with currency:%@", formattedString);
    [retDict setObject:formattedString forKey:@"basic_price"];
    NSLog(@"Product title: %@" , basicProduct.localizedTitle);
    NSLog(@"Product description: %@" , basicProduct.localizedDescription);
    NSLog(@"Product price: %@" , basicProduct.price);
    NSLog(@"Product id: %@" , basicProduct.productIdentifier);
Run Code Online (Sandbox Code Playgroud)

在委托方法中:

 - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
Run Code Online (Sandbox Code Playgroud)

这可以在用户点击开始购买东西之前完成.


brn*_*nes 6

在Swift 3中

    let numberFormatter = NumberFormatter()
    numberFormatter.formatterBehavior = .behavior10_4
    numberFormatter.numberStyle = .currency
    numberFormatter.locale = product.priceLocale
    let formattedPrice = numberFormatter.string(from: product.price)
Run Code Online (Sandbox Code Playgroud)


Kir*_* A. 5

您可以了解有关区域设置对象的更多信息,我认为您也可以使用NSLocale的货币区域设置,如下所示

 NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setLocale:[NSLocale currentLocale];
NSString *localizedMoneyString = [formatter stringFromNumber:myCurrencyNSNumberObject];
Run Code Online (Sandbox Code Playgroud)

你会得到这样正确的格式化货币字符串,

SKProduct *product = [self.products objectAtIndex:indexPath.row];
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setLocale:product.priceLocale];
currencyString = [formatter stringFromNumber:product.price];
Run Code Online (Sandbox Code Playgroud)

我也在我的应用程序中试过这个

NSDecimalNumber *amount = [NSDecimalNumber decimalNumberWithString:@"50.00"];
NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"Amount with symbol: %@", [currencyFormat stringFromNumber:amount]);//Eg: $50.00
NSLog(@"Current Locale : %@", [locale localeIdentifier]);//Eg: en_US
Run Code Online (Sandbox Code Playgroud)

希望它会对你有所帮助