iOS / Swift-消耗性应用内购买不断得到恢复

问题描述 投票:0回答:1

我已经实施了应用内购买,所有这些都将/将是可消费的。但是,由于某种原因,我的应用程序将它们视为非消耗品,并且每次都会恢复购买。首次实施应用内购买后,所有内容都会相应运行。

现在,我不断收到可怕的消息,表明是否已购买并恢复了应用内购买。

这是我的代码:

class IAPService: NSObject {
    private override init () {}
    static let shared = IAPService()
    var productDidPurchased: (() -> Void)?
    var products = [SKProduct]()
    let paymentQueue = SKPaymentQueue.default()



    func getProducts() {
        SKPaymentQueue.default().add(self)
        let products: Set = [IAPPProduct.tier1.rawValue]
        let request = SKProductsRequest(productIdentifiers: products)
        request.delegate = self
        request.start()
        paymentQueue.add(self)
    }

    func purchase(product: IAPPProduct) {
        guard let productToPurchase = products.filter({ $0.productIdentifier == product.rawValue  }).first else {return}
        let payment  = SKPayment(product: productToPurchase)
        paymentQueue.add(payment)


    }

    func restorePruchases() {
        print("restoring purchases")
        paymentQueue.restoreCompletedTransactions()
    }
}
extension IAPService: SKProductsRequestDelegate {
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        self.products = response.products
        for product in response.products {
            print(product.localizedTitle)
        }

    }
}

extension IAPService: SKPaymentTransactionObserver {
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            print(transaction.transactionState)
            print(transaction.transactionState.status(), transaction.payment.productIdentifier)
            switch transaction.transactionState {
            case .purchased:
                productDidPurchased?()
                queue.finishTransaction(transaction)
                break
            case .failed:
                queue.finishTransaction(transaction)
                break
            case .restored:
                queue.finishTransaction(transaction)
                break
            case .deferred:
                break
            case .purchasing:
                break
            }
        }
    }
}

extension SKPaymentTransactionState {
    func status() -> String {
        switch self {
        case .deferred:
            return "deferred"
        case .failed:
            return "failed"
        case .purchased:
            return "purchased"
        case .purchasing:
            return "purchasing"
        case .restored:
            return "restored"
        }
    }
} 

有人可以帮我解决这个问题吗?

谢谢。

ios swift in-app-purchase
1个回答
0
投票

我需要一些细节帮助兄弟们

© www.soinside.com 2019 - 2024. All rights reserved.