Xcode > Debug > Storekit > Manage Transactions显示交易状态为已购买,但状态为未完成?

ma8fv8wu  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(122)

bounty将在4天后过期。回答此问题可获得+50声望奖励。Lena Verhoev正在寻找一个规范的答案:想知道为什么交易被列为未完成,而过程显然已经完成。还有,如何解决?

下面的代码。我在调用updatedTransactions后调用SKPaymentQueue.default().finishTransaction(transaction)-不知道为什么Xcode的Storekit Transactions中的transaction状态是unfinished。

internal func purchaseFullVersion() {
        if let product = product {
            let payment = SKPayment(product: product)
            SKPaymentQueue.default().add(payment)
        }
    }

    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            switch transaction.transactionState {
            case .purchased : purchased(transaction: transaction)
            case .failed : failed(transaction: transaction)
            case .restored : restored(transaction: transaction)
            default : break
            }
        }
    }

    internal func purchased(transaction:SKPaymentTransaction) {
        SKPaymentQueue.default().finishTransaction(transaction)
        print("Purchased")
        guard let product = product else { return }
        purchaseTransactionComplete() // this updates UserDefaults
    }

字符串

n6lpvg4x

n6lpvg4x1#

extension PremiumScreen : SKPaymentTransactionObserver
{
    func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
        ProgressViewHide(uiView: self.view)
        showAlertMsg(Message: "Subscription Restored Successfully!", AutoHide: false)
        Subscribe.save(true)
    }
    func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
        ProgressViewHide(uiView: self.view)
    }
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        transactions.forEach({
            switch $0.transactionState {
            case .purchasing:
                print("purchasing")
            case .purchased:
                print("purchased")
                ProgressViewHide(uiView: self.view)
                SKPaymentQueue.default().finishTransaction($0)
                setHomeDashBoard()
            case .failed:
                print("failed")
                SKPaymentQueue.default().finishTransaction($0)
            case .restored:
                print("restored")
            case .deferred:
                break
            @unknown default:
                break
            }
        })
    }
}

字符串

相关问题