我在我的应用程序上添加了一个 UIAlertView,它有 UIActivityIndicatior 作为 subview 。 此 alertView 仅在购买正在进行时显示。我以这种方式将我的警报 View 放在我的 StoreObserver 中:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchasing:
[self stillPurchasing]; // this creates an alertView and shows
break;
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
break;
default:
break;
}
}
- (void) stillPurchasing {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"In App Purchase" message: @"Processing your purchase..." delegate: nil cancelButtonTitle: nil otherButtonTitles: nil];
self.alertView = alert;
[alert release];
UIActivityIndicatorView *ind = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
self.indicator = ind;
[ind release];
[self.indicator startAnimating];
[self.alertView addSubview: self.indicator];
[self.alertView show];
}
当我点击我的购买按钮时,这个 UIAlertView 会和我的 UIActivityIndicator 一起显示。但是当交易完成时,alertView 仍然在 View 的顶部并且 Indicator 是唯一被删除的。我的问题是我应该如何释放 alertView?或者我应该在哪里/什么时候发布它。
我添加了这些命令以在这些情况下释放我的 alertView 和 Indicator: 案例 SKPaymentTransactionStatePurchased: 案例 SKPaymentTransactionStateFailed: 案例 SKPaymentTransactionStateRestored:
[self.indicator stopAnimating];
[self.indicator removeFromSuperview];
[self.alertView release];
[self.indicator release];
我只添加了 alertView 来显示购买仍在进行中。任何向用户创建任何反馈的建议都会感谢我..
谢谢
最佳答案
要删除警报 View ,请使用
[alertView dismissWithClickedButtonIndex:0 animated:YES];
关于iphone - 在应用内购买正在进行时显示 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2726745/