在应用程序购买过程中显示UIAlertView

时间:2010-04-28 04:06:31

标签: iphone objective-c uialertview in-app-purchase

我添加了一个UIAlertView,它将UIActivityIndi​​catior作为我的应用程序的子视图。 此alertView仅显示购买正在进行的时间。我已经在我的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与我的UIActivityIndi​​cator一起显示..但是当事务完成时,alertView仍然在视图的顶部,并且指标是唯一被删除的。我的问题是我应该如何发布alertView?或者我应该何时/何时发布它。

我添加了这些命令以在这些情况下释放我的alertView和Indicator: 案例SKPaymentTransactionStatePurchased: 案例SKPaymentTransactionStateFailed: 案例SKPaymentTransactionStateRestored:

[self.indicator stopAnimating];
[self.indicator removeFromSuperview];
[self.alertView release];
[self.indicator release]; 

我只添加了alertView以显示购买仍在进行中。任何向用户提供反馈意见的建议都会让我感激不尽。

由于

1 个答案:

答案 0 :(得分:2)

要删除警报视图,请使用

[alertView dismissWithClickedButtonIndex:0 animated:YES];