我正在尝试通过非耗材购买启用In内置功能。我可以检索我的产品并进行购买,但是在持续购买时遇到了问题。当我购买产品时,我必须启用视图控制器中的按钮(最初禁用),并且我还保留一个标签,将其名称更改为“已购买”。购买后我的标签文本更改并启用按钮,但是当我停止并运行Xcode时标签状态只保留不是我的按钮,它会回到禁用状态。
**查看控制器**
-(void)Purchased {
Label.text = @"item has been purchased";
_newview.enabled=YES;
NSUserDefaults *saveapp = [NSUserDefaults standardUserDefaults];
[saveapp setBool:TRUE forKey:k_Save];
[saveapp synchronize];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSUserDefaults *saveapp = [NSUserDefaults standardUserDefaults];
bool saved = [saveapp boolForKey:k_Save];
if (!saved) {
/// not save code here
NSLog(@"wooo");
} else {
///saved code here
Label.text = @"item has been purchased";
}
// Do any additional setup after loading the view, typically from a nib.
}
**购买了视图控制器**
-(void)UnlockPurchase {
_buyButton.enabled = NO;
[_buyButton setTitle:@"Purchased" forState:UIControlStateDisabled];
[_homeViewController Purchased];
}
我在更新的事务委托函数中调用了这个“UnlockPurchase”。现在最糟糕的情况是购买后,这个“_buyButton”状态很快就会恢复启用。
此步骤是正确还是错误?如何让购买坚持下去?请帮忙!
答案 0 :(得分:1)
尝试在viewDidLoad方法中添加相同的代码(以启用按钮)...
…
bool saved = [saveapp boolForKey:k_Save];
….
} else {
///saved code here
Label.text = @"item has been purchased”;
//Disable BuyButton
//Enable your DesiredButton
}
<强> UPD 强>
将SKPaymentTransactionStateRestored
添加到您的方法中:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
...
case SKPaymentTransactionStateRestored:[self UnlockPurchase];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
....