所以我似乎無法讓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
}
}
}
看着這個庫,我想我會嘗試在我的應用中實現這個框架看起來更強大 – Tunds