IAPs are being restoring when they have not yet been purchased yet

梦想的初衷 提交于 2019-12-20 06:43:14

问题


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.



来源:https://stackoverflow.com/questions/39733428/iaps-are-being-restoring-when-they-have-not-yet-been-purchased-yet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!