【问题标题】:How to get Price Tier for InApp Purchase dynamically?如何动态获取 InApp 购买的价格等级?
【发布时间】:2013-05-06 06:11:46
【问题描述】:

我有一个应用程序,我在其中使用了 5 个消耗品应用内购买。

按钮上有应用内价格。

-我不想静态设置 In App 的值(例如 $0.99、$1.99 等等...)。

-我希望按钮上的价格动态显示在 iTunes 商店中。

是否可以从 iTunes 的 InApp 获取价格层并显示它?

【问题讨论】:

标签: ios objective-c in-app-purchase


【解决方案1】:

您通过以下方式请求SKProducts 的列表:

self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:self.productIdentifiers];
self.productsRequest.delegate = self;
[self.productsRequest start];

你需要实现SKProductsRequestDelegate。这有一个方法可以返回一个带有SKProducts 的数组。在具有上述代码的类中。

那么你需要这样的方法:

- (NSString*)localizedFormattedPrice:(SKProduct*)product
{
    NSString*          formattedString;
    NSNumberFormatter* numberFormatter;

    numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [numberFormatter setLocale:product.priceLocale];

    formattedString = [numberFormatter stringFromNumber:@(product.price)];

    return formattedString;
}

【讨论】:

  • 好的,我会试试这个,让你知道。感谢您的回复。
  • @meaning-matters 如何将 SKProductsRequest 转换为 SKProduct ?
  • @Rushi 这不是铸造而是请求。请参阅上面的扩展答案,
【解决方案2】:
NSNumberFormatter * _priceFormatter;

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

[_priceFormatter setLocale:product.priceLocale];
priceLabel.text = [_priceFormatter stringFromNumber:product.price];

【讨论】:

  • @ushan37:好的,我会检查并告诉你。感谢您的回复。
  • 我想在应用程序启动时在我的标签上显示价格等级。意味着当我打开上面显示的视图时,即使我没有按下这些按钮,该产品 ID 的价格层也应该在那里。有可能得到吗?因为只有当我按下 inapp 购买按钮时才会调用 inapp 的委托方法?等待您的回复。
  • 阅读本教程raywenderlich.com/21081/…,它涵盖了应用内购买的所有基础知识。您可以使用 SKProductsRequest 请求产品列表。您可以在代码中的任何位置执行此操作。我建议您阅读本教程
猜你喜欢
  • 1970-01-01
  • 2014-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多