2

我想在我的应用程序中实现年度订阅,我使用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)
    }
}

你有什么建议,我该如何解决?

4

1 回答 1

5

在我的情况下,这个问题的工作解决方案是:

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)
        }
    }
}
于 2017-01-12T17:50:10.653 回答