- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
SKPaymentTransactionObserver.paymentQueue:updatedTransactions 返回一组交易。当我付款时,我如何知道我付款的是哪笔交易?当我付款时,它总是返回一笔交易吗?
同时,这个观察者函数在恢复交易时也会被调用。那么,处理 updatedTransactions 的最佳实践是什么?
顺便说一句,我的订阅产品是自动续订订阅。
最佳答案
迭代交易循环并检查每笔交易。
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch (transaction.transactionState) {
case .purchased:
completeTransaction(transaction: transaction)
break
case .failed:
failedTransaction(transaction: transaction)
break
case .restored:
restoreTransaction(transaction: transaction)
break
case .deferred:
// TODO show user that is waiting for approval
break
case .purchasing:
break
}
}
}
private func completeTransaction(transaction: SKPaymentTransaction) {
print("completeTransaction...")
deliverPurchaseForIdentifier(identifier: transaction.payment.productIdentifier)
SKPaymentQueue.default().finishTransaction(transaction)
}
private func restoreTransaction(transaction: SKPaymentTransaction) {
guard let productIdentifier = transaction.original?.payment.productIdentifier else { return }
print("restoreTransaction... \(productIdentifier)")
deliverPurchaseForIdentifier(identifier: productIdentifier)
SKPaymentQueue.default().finishTransaction(transaction)
}
private func failedTransaction(transaction: SKPaymentTransaction) {
if let error = transaction.error as NSError? {
if error.domain == SKErrorDomain {
// handle all possible errors
switch (error.code) {
case SKError.unknown.rawValue:
print("Unknown error")
BaseViewController.currentViewController?.Alert(title: MFErrors.purchaseFaild.messgae.title, msg: MFErrors.purchaseFaild.messgae.body)
case SKError.clientInvalid.rawValue:
print("client is not allowed to issue the request")
BaseViewController.currentViewController?.Alert(title: MFErrors.accountNotAllowedToMakePurchase.messgae.title, msg: MFErrors.accountNotAllowedToMakePurchase.messgae.body)
case SKError.paymentCancelled.rawValue:
print("user cancelled the request")
case SKError.paymentInvalid.rawValue:
print("purchase identifier was invalid")
case SKError.paymentNotAllowed.rawValue:
print("this device is not allowed to make the payment")
BaseViewController.currentViewController?.Alert(title: MFErrors.purchaseFaild.messgae.title, msg: MFErrors.purchaseFaild.messgae.body)
default:
break;
}
}
ProgressViewManager.shared.hide()
}
SKPaymentQueue.default().finishTransaction(transaction)
}
private func deliverPurchaseForIdentifier(identifier: String?) {
guard let identifier = identifier else { return }
//Check if this transactions is a subscription
//SubscriptionsProductIdentifiers is an array of subscriptions product ids you sent to the app store to get SKProducts
//If subscription
if SubscriptionsProductIdentifiers.contains(identifier) {
}else{
//If non-consumable, consumables etc...
}
}
这是我之前回答中完整的商店经理: How to handle shouldAddStorePayment for In-App Purchases in iOS 11?
关于iOS IAP paymentQueue :updatedTransactions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47388711/
我正在构建一个包含应用内购买的应用。该应用程序有 6 种待售产品(全部为消耗品)。 该应用程序能够使用以下代码识别可供购买的产品(来自 itunes connect): override func v
SKPaymentTransactionObserver.paymentQueue:updatedTransactions 返回一组交易。当我付款时,我如何知道我付款的是哪笔交易?当我付款时,它总是返
我正在尝试使用以下代码进行交易: SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.this.is.where.
当用户在app purchase中重新购买时,paymentQueue::updatedTransactions应该被iOS调用吗? 情况是:如果用户重新购买产品,代码中没有调用任何内容,所以我无法将
当我点击我的任何一个 IAPS 时,会出现一条消息说 IAP 已经购买(事实并非如此)并将免费恢复,然后没有任何反应,IAP 不会执行。 这是我在控制台中得到的: No Value. IAP is e
我在 Swift 中有一个 iOS 应用程序,它实现了 paymentQueue(_:shouldAddStorePayment:for:) SKPaymentTransactionObserver
当我启动同一个 UIView 并有可能购买 InApp 可购买产品时,我有两个地方。1.用户入职结束2.菜单中的标准位置 从第一次付款开始,我通过 SKPaymentTransactionStateP
问题:我调用 [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; 它返回到我的观察者 paymentQueueRestoreCo
我是一名优秀的程序员,十分优秀!