我在这个板上尝试了几种解决方案,但从未成功。我想要的是当用户单击时Buy Button
,出现一个UIAlertView
withUIActivityIndicatorView
等待应用程序访问应用程序商店。UIAlertView
但是一旦购买完成,我不知道在哪里可以忽略它。我知道要解雇 a 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;
}
}
}