这段代码是苹果开发者网站为用户提供的内容,当用户点击推广的应用商店产品时,它会提示检查是否可以完成交易。我该如何进行检查呢?因为接下来我需要处理如果交易失败或延迟的情况,但似乎无法弄清楚如何做到这一点。
//MARK: - SKPaymentTransactionObserver
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment,
forProduct product: SKProduct) -> Bool {
// Check to see if you can complete the transaction.
// Return true if you can.
return true
}
我还需要处理下一个场景,我发现这与检查是否可以完成交易的情况相同
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment,
forProduct product: SKProduct) -> Bool {
// ... Add code here to check if your app must defer the transaction.
let shouldDeferPayment = ...
// If you must defer until onboarding is completed, then save the payment and return false.
if shouldDeferPayment {
self.savedPayment = payment
return false
}
// ... Add code here to check if your app must cancel the transaction.
let shouldCancelPayment = ...
// If you must cancel the transaction, then return false:
if shouldCancelPayment {
return false
}
}
// (If you canceled the transaction, provide feedback to the user.)
// Continuing a previously deferred payment
SKPaymentQueue.default().add(savedPayment)
)
如何检查支付是否失败,是否需要推迟或可以像代码部分所示那样完成?