iOS“此应用内购买已被购买”弹出 [英] iOS "This in-app purchase has already been bought" pop-up

查看:720
本文介绍了iOS“此应用内购买已被购买”弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS应用程序出现问题:当我触摸购买按钮购买IAP产品时,会出现一个弹出窗口显示此消息:

I'm getting an issue on my iOS app: when I touch the 'buy' button to purchase an IAP product, a pop-up appears showing this message:

此应用内购买已被购买。它将免费恢复。

This In-App purchase has already been bought. It will be restored for free.

之前从未有过弹出窗口,我的产品仅不续订订阅,所以我想知道为什么在购买订阅时会出现此消息。

I never had this pop-up before, and my products are only non-renewing subscriptions, so I wonder why this message appears when buying subscriptions.

当我触摸确定关闭此弹出窗口时,不执行购买。

When I touch ok to close this pop-up, the purchase is not performed.

这是我的代码:

for transaction in transactions {
        switch transaction.transactionState {

        case SKPaymentTransactionState.Purchased, SKPaymentTransactionState.Restored:
            print("Transaction completed successfully.")
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false
            // Sauvegarde le produit acheté
            savePurchasedProduct(transaction.transactionDate!);
            break

        case SKPaymentTransactionState.Failed:
            print("Transaction Failed");
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false
            break

        default:
            break
        }
    }


推荐答案

我遇到了同样的问题。修复此问题:我的IAP无效。 func Paymentqueue的错误

I had the same issue. Fixed it here: My IAP isn't working. Bugs at func Paymentqueue

这是我找到的解决方案:

Here is the solution I had found:

删除

SKPaymentQueue.defaultQueue().addTransactionObserver(self) 

你到处都有它并且只在你每次启动应用程序时执行一次(仅限一次)(我把它放在viewDidLoad()中)。

everywhere you have it and put it once (ONLY ONCE) in a place where it will be executed each time your app boots up ( I put it in viewDidLoad()).

这将检查所有未完成的交易,并在应用程序加载后终止它们,从而在用户触发IAP之前删除任何可能的错误。

This will check for all unfinished transactions and terminate them once the app has loaded, thus removing any possible errors before your users triggers an IAP.

(如果这个答案有所帮助,请不要忘记upvote;))

(If this answer helped you, don't forget to upvote ;))

PS:此外,这不是我的问题,但要确保每个PurchaseState的finishTransaction(),如下所示:

P.S.: Also, this wasn't my issue, but make sure to finishTransaction() for each PurchaseState, like here:

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        print("Add Payment")

        for transaction:AnyObject in transactions{
            let trans = transaction as! SKPaymentTransaction
            print(trans.error)
            switch trans.transactionState{
            case .Purchased:
                print("IAP unlocked")
                print(p.productIdentifier)

                let prodID = p.productIdentifier as String
                switch prodID{
                case "IAP id":
                    print("Keep on")
                    keepOn()
                default:
                    print("IAP not setup")
                }
                queue.finishTransaction(trans)
                break
            case .Failed:
                print ("Buy error")
                queue.finishTransaction(trans)
                break
            default:
                print("default: Error")
                break
            }
        }
    }

永远不要忘记这一点:

 queue.finishTransaction(trans)  

这篇关于iOS“此应用内购买已被购买”弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆