如何在 ios 中检测系统弹出视图的 "Cancel" 按钮?

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

正在为应用程序编写应用程序内购买代码,与 iTunes 商店连接时会显示 Activity 指示符。并且 Activity 指示器可以在连接正常完成时停止,但以下情况除外:

有两个 "Cancel" 按钮: 1. select 购买时,系统会显示带有 "Cancel" 按钮的 itunes 商店登录视图。 2.如果输入密码继续,如果之前购买过该产品,另一个"Cancel"按钮可以return。

由于 Activity 指示器在第 1 步开始动画,如果按下两个 "Cancel" 按钮中的任何一个将完成该过程,但 Activity 指示器仍在旋转,因为我无法抓住取消按钮。

我已经尝试了 "alertView" 和 "actionSheet" 来获取 buttonIndex,但它们在自定义 alertView 中总是有效。

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

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

如有任何建议,我们将不胜感激。

为了检测应用内购买何时被取消,您必须设置一个 SKPaymentTransactionObserver,当交易状态发生变化时它会收到通知。特别是,当事务更改为 SKPaymentTransactionStateFailed 状态时,您会感兴趣,然后您可以关闭 Activity 指标。

有关 objective-c 实施,请参阅 here