所以我似乎无法在尝试恢复购买时触发 updatedTransactions
协议(protocol)。
我在一个 View Controller 中有一个按钮,它在我的 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
}
}
}
最佳答案
您的 Controller 是否使用 SKPaymentQueue.defaultQueue().addTransactionObserver(..)
添加为观察者?
关于ios - swift 恢复购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34935122/