gpt4 book ai didi

ios - 显示应用内购买的本地化价格

转载 作者:可可西里 更新时间:2023-11-01 04:35:08 58 4
gpt4 key购买 nike

我在我的 ViewController 中使用以下代码,但是当我调用 _priceFormatter 时,它会将价格显示为 (null)

 [buyButton setTitle:[NSString stringWithFormat:@"Upgrade for %@", [_priceFormatter stringFromNumber:product.price]] forState:UIControlStateNormal];

ViewController.m

{


NSNumberFormatter * _priceFormatter;


}

ViewDidLoad

    [RageIAPHelper sharedInstance];

_products = nil;

[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;

}
}];

SKProduct * product = (SKProduct *) [_products objectAtIndex:0];


([[RageIAPHelper sharedInstance] productPurchased:product.productIdentifier]);

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

[_priceFormatter stringFromNumber:product.price];

已编辑

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

NSString *priceString = [_priceFormatter stringFromNumber:product.price];

按钮:

    UIButton *buyButton = [[UIButton alloc] initWithFrame:CGRectMake(-1, 370, 320, 60)];
[buyButton setTitle:[NSString stringWithFormat:@"Upgrade for %@", priceString] forState:UIControlStateNormal];
[buyButton.titleLabel setFont:[UIFont boldSystemFontOfSize:13.0]];
[buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[buyButton.titleLabel setShadowColor:[UIColor colorWithWhite:0.1 alpha:1.0]];
[buyButton.titleLabel setShadowOffset:CGSizeMake(0, -1)];
[buyButton addTarget:self action:@selector(buyButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
buyButton.tag = 0;
[[self view] addSubview:buyButton];

最佳答案

您需要等到调用完成处理程序来处理产品:

[RageIAPHelper sharedInstance];
_products = nil;

[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;

SKProduct * product = _products[0];

[[RageIAPHelper sharedInstance] productPurchased:product.productIdentifier];

_priceFormatter = [[NSNumberFormatter alloc] init];
[_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[_priceFormatter setLocale:product.priceLocale];
NSString *price = [_priceFormatter stringFromNumber:product.price];
someLabel.text = price;
}
}];

如您所见,您需要实际使用格式化的数字字符串。你只是在丢弃值(value)。

关于ios - 显示应用内购买的本地化价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21244021/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com