2016-01-21 125 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

,你是好去。