show UIAlertView when In app purchase is in progress

Posted by edie on Stack Overflow See other posts from Stack Overflow or by edie
Published on 2010-04-28T04:06:31Z Indexed on 2010/04/28 4:13 UTC
Read the original article Hit count: 329

Hi...

I've added an UIAlertView that has UIActivityIndicatior as a subview on my application. This alertView only show when the purchase is in progress. I've put my alert view in this way in my 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];
}

When I tap my the buy button this UIAlertView shows together with my UIActivityIndicator.. But when the transaction completes the alertView still on the top of the view and the Indicator was the only one that was removed. My question was how should I release the alertView? Or where/When should I release it.

I've added these command to release my alertView and Indicator on these cases: case SKPaymentTransactionStatePurchased: case SKPaymentTransactionStateFailed: case SKPaymentTransactionStateRestored:

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

I've only added the alertView to show that the purchasing was still in progress. Any suggestion to create any feedback to users will be thankful for me..

Thanks

© Stack Overflow or respective owner

Related posts about uialertview

Related posts about in-app-purchase