我想在我的应用中实现年度订阅,我使用StoreKit
来完成。问题是,当我点按subscriptionButton
时。一个应用程序抛出错误:'NSInvalidArgumentException', reason: 'Cannot finish a purchasing transaction'
。我被困在这个地方,无法解决我的问题。所以,我的paymentQueue
代码看起来像这样:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
print(transactions)
for transaction in transactions {
print(transaction.error ?? "")
switch transaction.transactionState {
case .deferred:
print("deffered")
case let .failed(err):
print("failed: \(err)")
case .purchased:
let productID = p.productIdentifier
selectProduct(productID: productID)
case .purchasing:
print("purhasing")
print("produkt name: \(p.localizedTitle)") // after executing this line of code app crashes
case .restored:
let productID = p.productIdentifier
selectProduct(productID: productID)
}
queue.finishTransaction(transaction)
}
}
您有什么建议,我该如何解决?
答案 0 :(得分:3)
在我的案例中解决这个问题的方法是:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
print(transaction.error ?? "")
switch transaction.transactionState {
case .deferred:
print("deffered")
queue.finishTransaction(transaction)
case let .failed(err):
print("failed: \(err)")
queue.finishTransaction(transaction)
case .purchased:
let productID = p.productIdentifier
selectProduct(productID: productID)
queue.finishTransaction(transaction)
case .purchasing:
print("purhasing")
case .restored:
let productID = p.productIdentifier
selectProduct(productID: productID)
queue.finishTransaction(transaction)
}
}
}