我在这个主板上尝试了几种解决方案,但从未成功过。我想要的是当用户点击Buy Button
时,UIAlertView
会出现UIActivityIndicatorView
,等待应用访问应用商店。但是一旦购买完成,我不知道在哪里解雇这个UIAlertView
。我知道要解雇UIAlertView
,我们会使用:[alert dismissWithClickedButtonIndex:-1 animated:YES];
那么请你帮我回答两个问题:
1)我的代码是否正常或其他任何更好的代码来实现它?
2)对于所有情况,我应该在哪里解雇UIAlertView
:
以下是我的代码:
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
UIAlertView *alert;
for(SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
alert = [[UIAlertView alloc]initWithTitle: @"In App Purchase" message: @"Processing your purchase..." delegate: nil cancelButtonTitle: nil otherButtonTitles: nil];
UIActivityIndicatorView *ind = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
[ind startAnimating];
[alert addSubview: ind];
[alert show];
[ind release];
[alert release];
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Complete"
message:@"You have bought the full version!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
[tmp release];
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code !=SKErrorPaymentCancelled) {
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Purchase not successful!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
[tmp release];
}
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
}
}
}
答案 0 :(得分:0)
尝试添加
case SKPaymentTransactionStatePurchased:
[alert dismissWithClickedButtonIndex:-1 animated:YES];
和
case SKPaymentTransactionStateFailed:
[alert dismissWithClickedButtonIndex:-1 animated:YES];