0

我有和 appdelegate 在 init 方法期间请求 AppStore 产品详细信息,并且我想将应用内购买产品的价格显示到弹出框内的按钮中。

我已经设置了正确返回产品数组的请求,以及包含价格的字符串。我的问题是弹出视图控制器在 AppStore 回复之前创建视图,并且标题标签初始化为 (null)。如果我可以延迟按钮标题集,我会确定请求确实得到了回复,但这会使应用程序崩溃。

我的要求是

- (void)requestProUpgradeProductData {
NSSet *productIdentifiers = [NSSet setWithObject:@"com.thePrintLabs.product"];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];

}

然后我阅读了回复:

NSArray *products = response.products;
proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain] : nil;
if (proUpgradeProduct)
{
NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
NSLog(@"Product price: %@" , proUpgradeProduct.price);
NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);


NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
priceWeek = [NSString stringWithString:[formatter stringFromNumber:proUpgradeProduct.price]];
}

在 popOverViewController 我这样做是为了设置按钮标题:

myAppDelegate *delegate = (myAppDelegate*)[[UIApplication sharedApplication] delegate];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
           action:@selector(button1Week:)
 forControlEvents:UIControlEventTouchDown];
NSString *priceWeekly = [NSString stringWithFormat:@"Weekly %@",delegate.priceWeekly];
[button setTitle:priceWeekly forState:UIControlStateNormal];

我的按钮总是用(null)初始化。请求成功后可以更新按钮吗?

4

0 回答 0