My IAP isn’t working. Bugs at func Paymentqueue

I found the solution !

Delete

SKPaymentQueue.defaultQueue().addTransactionObserver(self) 

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()).

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.

(If this answer, or this question helped you, don’t forget to upvote ;))

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

Never forget this:

 queue.finishTransaction(trans)  

Leave a Comment