My IAP isn't working. Bugs at func Paymentqueue

前端 未结 1 1704
礼貌的吻别
礼貌的吻别 2020-11-29 12:40

When I click on either of my IAPS, a message appears saying the IAP was already purchased (which is not the case) and will be restored for free, then nothing happens, the I

相关标签:
1条回答
  • 2020-11-29 13:39

    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)  
    
    0 讨论(0)
提交回复
热议问题