在SKPaymentTransaction

时间:2016-01-23 00:07:55

标签: ios swift storekit

我一直在尝试创建订阅系统,这让我很伤心。 我现在来到这个问题。因此用户进入并且需要一些时间才能弹出来自iTunes的警报。我决定放置加载警报,但我不知道何时停止它。我不知道在哪里放置这种方法。

这是我的代码:

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction:AnyObject in transactions {
        if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
            switch trans.transactionState {

            case .Purchasing:
                let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .Alert)
                alert.view.tintColor = UIColor.blackColor()
                let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(10, 5, 50, 50)) as UIActivityIndicatorView
                loadingIndicator.hidesWhenStopped = true
                loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
                loadingIndicator.startAnimating();
                alert.view.addSubview(loadingIndicator)
                presentViewController(alert, animated: true, completion: nil)
                break
            case .Purchased:
                self.validateReceipt()
                //self.setExpirationDate()
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                //dismissViewControllerAnimated(false, completion: nil)
                break
            case .Failed:
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                print("Not called Expired")
                break
            case .Restored:
                SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
                print("Restored")
                break
            default:
                //dismissViewControllerAnimated(false, completion: nil)
                break
            }
        }
    }
}

这是dismissViewControllerAnimated(false, completion: nil) 用于关闭加载警报。

0 个答案:

没有答案