2016-01-21 119 views
4

所以我似乎无法让updatedTransactions协议在尝试恢复购买时触发。迅速恢复购买

我在一个视图控制器中有一个按钮,它在我的IAPViewController文件restoreIAP()中调用以下方法,它是这样设置的。

func restoreIAP(){ 

    SKPaymentQueue.defaultQueue().restoreCompletedTransactions() 
} 

当用户按下按钮时调用此方法,因此这是处理此类的类。

class SettingsViewController: IAPViewController { 


    @IBAction func restoreDidTouch(sender: AnyObject) { 

     restoreIAP() 
     activityTitle = "Restoring" 

    } 

} 

在我IAPViewController似乎没有什么可以触发这个方法,这样我可以做一些事情。

// Check the transaction 
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { 

    // Check the tranactions 

    for transaction in transactions { 

     switch transaction.transactionState { 

     case .Purchasing: 
      // TODO: Start Activity Indicator 
      showPurchaseIndicator(activityTitle) 
      break 

     case .Purchased: 
      // TODO: End the purchasing activity indicator 
      dismissPurchaseIndicator() 
      print("Transaction completed successfully.") 
      SKPaymentQueue.defaultQueue().finishTransaction(transaction) 
      transactionInProgress = false 

      // TODO: Put method here to unlock all news sources 
      storiesMethods.unlockAllStories() 
      break 

     case .Restored: 
      // TODO: Start Activity Indicator 
      // showPurchaseIndicator(activityTitle) 
      break 

     case .Failed: 
      dismissPurchaseIndicator() 
      notificationMethods.showAlertErrorMessage(self, title: "Purchase", actionMessage: "Dismiss", message: "Unable to complete transaction please try again later.") 
      SKPaymentQueue.defaultQueue().finishTransaction(transaction) 
      transactionInProgress = false 
      break 

     default: 
      print(transaction.transactionState.rawValue) 
      break 
     } 
    } 

} 

回答

0

从你的描述和代码片段看起来一切都在正确的顺序。

如果paymentQueue函数没有被调用,您IAPViewController可能不符合SKPaymentTransactionObserver协议,只是使它遵循:

class IAPViewController: UIViewController, SKPaymentTransactionObserver

,你是好去。