针对受IPV6影响的非消费品的iOS In-App购买

时间:2016-07-19 00:31:41

标签: ios swift in-app-purchase ipv6

我使用Swift实现IAP来解锁我的游戏阶段。它在IPv4上运行良好。所以我提交这个二进制文件进行审核,当他们在IPv6网络上测试时被Apple拒绝。

拒绝二进制原因:

  

我们在连接到IPv6网络的Wi-Fi上运行iOS 9.3.2的iPhone上查看了应用中的一个或多个错误。   具体来说,在我们购买In App Purchase后,该级别无法解锁。

我为每个案例都设置了断点,但是当我在IPv6网络上运行时,程序没有进入任何一个案例。

这里是我购买的代码:

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])    {
    print("Received Payment Transaction Response from Apple");

    for transaction:AnyObject in transactions {
        if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
            switch trans.transactionState {
            case .Purchased:
                print("Product Purchased");
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                self.levelButtonHalloween.enabled = true
                lockImage.removeFromSuperview()
                Overlay.removeFromSuperview()
                userSettingDefaults.setBool(true, forKey: "enableHalloween")
                userSettingDefaults.synchronize()
                DesertOver50 = userSettingDefaults.boolForKey("enableHalloween")
                buyBottom.removeFromSuperview()
                backgroundImage.removeFromParent()
                backgroundImage = SKSpriteNode(imageNamed: "StageSelect_Background2")
                backgroundImage.size = self.frame.size
                backgroundImage.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
                backgroundImage.anchorPoint = CGPointMake(0.5, 0.5)
                backgroundImage.zPosition = 0
                addChild(backgroundImage)
                break;
            case .Failed:
                print("Purchase Failed");
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                break;
            case .Restored:
                print("Transaction restored")
                SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
                self.levelButtonHalloween.enabled = true
                lockImage.removeFromSuperview()
                Overlay.removeFromSuperview()
                userSettingDefaults.setBool(true, forKey: "enableHalloween")
                userSettingDefaults.synchronize()
                DesertOver50 = userSettingDefaults.boolForKey("enableHalloween")
                buyBottom.removeFromSuperview()
                backgroundImage.removeFromParent()
                backgroundImage = SKSpriteNode(imageNamed: "StageSelect_Background2")
                backgroundImage.size = self.frame.size
                backgroundImage.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
                backgroundImage.anchorPoint = CGPointMake(0.5, 0.5)
                backgroundImage.zPosition = 0
                addChild(backgroundImage)
            default:
                break;
            }
        }
    }
    SKPaymentQueue.defaultQueue().removeTransactionObserver(self)
}

我还实现了恢复购买按钮,它适用于ipv4和ipv6。

这里是恢复购买的代码:

func restorePurchaseButtonAction(){
    button_Clicked()
    if (DesertOver50 == false){
        if (SKPaymentQueue.canMakePayments()) {
            // Enable SKPayment as soon as possible during viewdidload
            SKPaymentQueue.defaultQueue().addTransactionObserver(self)
            SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
        }
    }else{
        let alert = UIAlertController(title: "It's already unlocked ¬_¬", message: "Your have already unlocked or purchased the item(s)", preferredStyle: .ActionSheet)
        let ok = UIAlertAction(title: "OK", style: .Cancel) { action -> Void in
        }
        alert.addAction(ok)
        alert.popoverPresentationController?.sourceView = view
        alert.popoverPresentationController?.sourceRect = self.frame
        self.view?.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil)
    }
}

以前有人有经验吗? IPv4与IPv6有什么不同的IAP实现?接下来我该怎么办?

2 个答案:

答案 0 :(得分:1)

您是否在ItunesConnect中检查您的设置是否正确注册了应用内购买?记得放

  

SKPaymentQueue.defaultQueue()。addTransactionObserver(个体)

在viewDidLoad中

。这个问题一直困扰着我。

答案 1 :(得分:1)

感谢您的建议。我的ituneConnect似乎没问题。

SKPaymentQueue.defaultQueue().addTransactionObserver(self)是根本原因 我的问题。

场景1: 物品完全购买但阶段未解锁=>失败

func buyNonConsumable() {
    button_Clicked()
    print("About to fetch the products");
    SKPaymentQueue.defaultQueue().addTransactionObserver(self)      
    // We check that we are allow to make the purchase.
    if (SKPaymentQueue.canMakePayments()) {
        let productID:NSSet = NSSet(object: self.product_id!);
        let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>);
        productsRequest.delegate = self;
        productsRequest.start();
        print("Fething Products");
    } else {
        print("can't make purchases");
    }
}

场景2:当app开始时,项目自动解锁,无需登录=&gt;失败

override func didMoveToView(view: SKView) {  
// In-App button and function call
    if(DesertOver50 == false) {
        product_id = "xxxxxxxx";
        SKPaymentQueue.defaultQueue().addTransactionObserver(self)     
        addBotton();

场景3:正常运作

func buyProduct(product: SKProduct) {
    print("Sending the Payment Request to Apple");
    let payment = SKPayment(product: product)
    SKPaymentQueue.defaultQueue().addPayment(payment);
    SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}

根据我的理解,情景2应该是最佳解决方案,但它失败了。 由于代码现在运行良好,我认为方案3是解决方案。