IAP正在恢复尚未购买的时候

时间:2016-09-27 20:07:56

标签: ios swift storekit

当用户调用restorePurchases()时,即使他们不拥有它,也会恢复非耗材com.premium。 以下是负责恢复购买和购买IAP的功能。这只是非耗材IAP的问题。 购买没有问题。如果用户尝试购买他们已经拥有的IAP,则只需恢复。感谢您关注此事。

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")
        }
    }

这也是我的付款队列。

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 个答案:

答案 0 :(得分:5)

您不应更新.scroller { scroll-snap-type: mandatory; scroll-snap-destination: 0% 100%; scroll-snap-points-x: repeat(100%); } 中的任何购买状态。此功能只是让您知道恢复过程已完成。您可以使用它来更新UI或显示警报或其他内容。

恢复过程将要恢复的事务传递到paymentQueueRestoreCompletedTransactionsFinished函数,您处理updatedTransactions状态的方式与处理.restored状态的方式相同。

基本上"恢复"只是重播非消耗品和自动续订订购购买类型的购买交易流程。