ios – How do I detect if SKProduct already purchased as consumable in app purchases before?

0
26

[ad_1]

I imported StoreKit and set my code for consumable purchase and set a sandbox tester. I have three buttons. Each one will buy a separate product. Here is my problem:

When my sandbox tester tries to purchase the same product again and presses the same button, Firebase analytics says:

“Purchase is a duplicate and will not be reported”.

Ok, fine. But how I can get this as a response from AppStore? Where does Firebase get this from?

When I look at SKPaymentTransaction.transactionState enum, there is no case about it. I tried to check cases and print something to console, like this:

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

I also checked transaction.error, but no error either.

This code prints nothing when the purchase fails from duplicate purchase. How can I get at least an error here?

What should I do?

My goal is show an alert and tell the client “You already purchased this”.

[ad_2]