SKScene 中的应用内购买不起作用?

In app purchase in SKScene not working?

我正在 Swift 中创建一个 SpriteKit 游戏,我正在尝试在应用程序购买中实施。

我在这里关注了这个问题:

这是我的代码:

在 didMoveToView 中:

 // Set IAPS
        if(SKPaymentQueue.canMakePayments()) {
            println("IAP is enabled, loading")
            var productID:NSSet = NSSet(objects: "GameOverSaveSavior")
            var request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as Set<NSObject>)
            request.delegate = self
            request.start()
        } else {
            println("please enable IAPS")
        }

在 didMoveToView 之外但在 GameScene 中:

 //IN APP PURCHASE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    var productList = [SKProduct]()
    var p = SKProduct()

    func purchaseMade() {
        println("they bought it!")
    }

    func buyProduct() {
        println("buy" + p.productIdentifier)

        var pay = SKPayment(product: p)
        SKPaymentQueue.defaultQueue().addTransactionObserver(self)
        SKPaymentQueue.defaultQueue().addPayment(pay as SKPayment)
    }
    func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
        println("product request")
        var myProduct = response.products

        for product in myProduct {
            println("product added")
            println(product.productIdentifier)
            println(product.localizedTitle)
            println(product.localizedDescription)
            println(product.price)

            productList.append(product as! SKProduct)
        }
    }

    func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) {
        println("transactions restored")

        var purchasedItemIDS = []
        for transaction in queue.transactions {
            var t: SKPaymentTransaction = transaction as! SKPaymentTransaction

            let prodID = t.payment.productIdentifier as String

            switch prodID {
            case "GameOverSaveSavior":

                purchaseMade()

                //Right here is where you should put the function that you want to execute when your in app purchase is complete
            default:
                println("IAP not setup")
            }

        }

        var alert = UIAlertView(title: "Thank You", message: "Your purchase(s) were restored. You may have to restart the app before banner ads are removed.", delegate: nil, cancelButtonTitle: "OK")
        alert.show()
    }


    func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
        println("add paymnet")

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

            switch trans.transactionState {

            case .Purchased, .Restored:
                println("buy, ok unlock iap here")
                println(p.productIdentifier)

                let prodID = p.productIdentifier as String
                switch prodID {
                case "GameOverSaveSavior":

                    //Here you should put the function you want to execute when the purchase is complete
                    var alert = UIAlertView(title: "Thank You", message: "You may have to restart the app before the banner ads are removed.", delegate: nil, cancelButtonTitle: "OK")
                    alert.show()
                default:
                    println("IAP not setup")
                }

                queue.finishTransaction(trans)
                break;
            case .Failed:
                println("buy error")
                queue.finishTransaction(trans)
                break;
            default:
                println("default")
                break;

            }
        }
    }

    func finishTransaction(trans:SKPaymentTransaction)
    {
        println("finish trans")
    }
    func paymentQueue(queue: SKPaymentQueue!, removedTransactions transactions: [AnyObject]!)
    {
        println("remove trans");
    }

 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

In touchesBegan 用于触摸应用内购买节点时:

//In app purchase
            if touchedNode == saveMeBtn {

                println("button touched!")
                for product in productList {
                    var prodID = product.productIdentifier
                    if(prodID == "GameOverSaveSavior") {
                        p = product
                        buyProduct()  //This is one of the functions we added earlier
                        break;
                    }
                }

我所有的代码都是直接来自上面的问题,代码编译没有任何错误并且

IAP is enabled, loading

product request

在游戏开始时打印到控制台。

触摸应用内购买按钮时,

button touched!

打印到控制台,但没有其他任何反应。它不要求用户购买任何东西。

我确保 Xcode 中的捆绑包 ID 与 iTunes Connect 中的相同,并且应用内购买 ID 相同。我在这里做错了什么?

经过几个星期的努力,我发现您必须完整填写并接受 付费应用程序 协议,您的代码和产品才能正常工作。批准可能需要几天时间,然后你就没事了。