How to detect "Cancel" button of system popup view in ios?

1.1k views Asked by At

am coding in-app purchase for the App, an Activity Indicator is shown when connecting with the itunes store. and the Activity Indicator can be stop when the connection finish in normal except the following:

There are two "Cancel" buttons: 1. When select purchase, system will show a itunes store login view with "Cancel" button. 2. If input password and go on, and if the product's been purchased before, another "Cancel" button could return.

Since the Activity Indicator's started animation at the step 1, if press any of the two "Cancel" button will finish the process, but the Activity Indicator's still spinning because I cannot catch the Cancel button.

I'v tried both "alertView" and "actionSheet" to get the buttonIndex, but they didn't work which always work in custom alertView.

func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){
    println(buttonIndex)
}

func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {
     println(buttonIndex)
}

Any suggestion will be appreciated.

1

There are 1 answers

1
duncanc4 On BEST ANSWER

In order to detect when the in-app purchase is canceled, you will have to setup a SKPaymentTransactionObserver which will be notified when a transaction changes states. In particular, you would be interested when the transaction changes to the SKPaymentTransactionStateFailed state, you can then dismiss the Activity Indicator.

See here for the objective-c implementation.