我已经购买了应用程序,并且运行良好。这是我在InAppPurchaseObserver.m中拥有的内容:
case SKPaymentTransactionStatePurchased:
// Item was successfully purchased!
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isProUpgradePurchased" ];
[[NSUserDefaults standardUserDefaults] synchronize];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
break;
case SKPaymentTransactionStateRestored:
// Verified that user has already paid for this item.
// Ideal for restoring item across all devices of this customer.
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isProUpgradePurchased" ];
[[NSUserDefaults standardUserDefaults] synchronize];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
break;
在我的ViewController中,我正在这样做:
if([[NSUserDefaults standardUserDefaults] boolForKey:@"isProUpgradePurchased"]) {
[energeeButton setImage:[UIImage imageNamed:@"thumb_unlocked_off.png"] forState:UIControlStateNormal];
}
在我重新启动应用程序后,该方法就可以工作,但是我希望在应用程序内购买完成后立即更改按钮图像。
我如何做到这一点?
谢谢!
最佳答案
当该值更改时,您需要向viewcontroller发送各种通知,以便它可以重新加载该特定图像
[[NSNotificationCenter defaultCenter] postNotificationName:@"DZCustomNotification" object:nil];
// put this right after you change the user defaults
// put this in the initializer of your viewcontroller
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(purchasedChanged:) name:@"DZCustomNotification" object:nil];
// create this instance method in your viewcontroller class
- (void)purchasedChanged:(NSNotification *)notif {
if([[NSUserDefaults standardUserDefaults] boolForKey:@"isProUpgradePurchased"]) {
[energeeButton setImage:[UIImage imageNamed:@"thumb_unlocked_off.png"] forState:UIControlStateNormal];
}
}
有呀!
关于ios - 在App Purchase中可以正常使用,但是付款成功后我无法更改UIButton图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8109984/