Show UIAlertView when in app purchase process

I added a UIAlertView that has a UIActivityIndicatior as a subview in my application. This alertView is shown only upon purchase. In my StoreObserver, I set my warning this way:

- (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 click the buy button, this UIAlertView shows along with my UIActivityIndicator identifier. But when the transaction completes the alertView at the top of the view, and the indicator was the only one that was deleted. My question is: how should I remove alertView? Or where / When should I let him go.

I added this command to issue my alertView and indicator in these cases: case SKPaymentTransactionState Bought: case SKPaymentTransactionStateFailed: case SKPaymentTransactionStateRestored:

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

alertView, , . .

+3
1

,

[alertView dismissWithClickedButtonIndex:0 animated:YES];
+2

Source: https://habr.com/ru/post/1743107/


All Articles