IAPs are being restoring when they have not yet be

2019-03-06 04:01发布

问题:

When the user calls restorePurchases(), the non-consumable com.premium is restored even thought they do not own it. Here are the functions that are responsible for the restoring purchases and purchasing IAPs. This is only an issue with non-consumable IAPs. There is no issue with purchasing. And if the user attempts to purchase an IAP that they already have, it is simply restored. Thank you for looking in to this.

func restorePurchases() {
    SKPaymentQueue.default().add(self)
    SKPaymentQueue.default().restoreCompletedTransactions()
}

func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
    print("transactions restored")

    for transaction in queue.transactions {
        let t: SKPaymentTransaction = transaction 

        let prodID = t.payment.productIdentifier as String
        print("starting restoring")
        switch prodID {
        case "com.premium":
            print("restoring ads")
            removeAds()
        case "com.cash":
            print("we dont restore coins")
        case "com.level":
            print("we dont restore levels")
        default:
            print("can't restore")
        }
    }

Here is my payment queue also.

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    print("add paymnet")

    for transaction:AnyObject in transactions {
        let trans = transaction as! SKPaymentTransaction
        print(trans.error)

        switch trans.transactionState {

        case .purchased:
            print("buying, ok unlock iap here")
            print(p.productIdentifier)

            let prodID = p.productIdentifier as String
            switch prodID {
            case "com.premium":
                print("buying ads")
                removeAds()
            case "com.cash":
                print("buying coins")
                addCoins()
            case "com.level":
                print("buying levels")
                addLevels()
            default:
                print("can't buy")
            }

            queue.finishTransaction(trans)
            break;
        case .failed:
            print("buy error")
            queue.finishTransaction(trans)
            break;
        default:
            print("default")
            break;

        }
    }
}

回答1:

You should not update any purchase status in paymentQueueRestoreCompletedTransactionsFinished. This function just lets you know that the restoration process has completed. You could use this to update your UI or display an alert or something.

The restoration process delivers the transactions to be restored to the updatedTransactions function where you handle the .restored state in the same way that you handle the .purchased state.

Essentially "restore" just replays the purchase transaction process for non-consumable and auto-renewing subscription purchase types.