code not working :/

}else if nodeArray.first?.name == "Restore"{
                if SKPaymentQueue.canMakePayments() == true{
                SKPaymentQueue.default().add(self)
                SKPaymentQueue.default().restoreCompletedTransactions()
                }







func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
        let alert = UIAlertController(title: "Completed", message:"All your previous purchases have been restored", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in })
        let rootVC = UIApplication.shared.keyWindow?.rootViewController
        rootVC?.present(alert, animated: true){}
    }
   
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction: AnyObject in transactions {
            let trans = transaction as! SKPaymentTransaction
            switch trans.transactionState {
            case .purchased, .restored:
                let prodID = p.productIdentifier
                switch prodID {
                case "com.Carawind.FlipFlop.RemoveAds":
                    AdBtn = true
                    UserDefaults.standard.set(true, forKey: "RemovedAds")
                    RemoveAdsBtn.removeFromParent()
                    self.viewController.HideAds()
                default: break
                  
                }
                queue.finishTransaction(trans)
            case .failed:
               
                queue.finishTransaction(trans)
                break
           
            default:
                break
               
            }
           
           
        }
    }

I am using a sandbox tester account to try to restore the purchases, but nothing happens besides giving me the alert that I created. Any help is welcome. Thank you

If you are saying that you see the alert "Completed" but never get a call to updatedTransactions then that means there are no transactions to restore. But you don't know whether you get a call to updatedTransactions do you? Add "NSLog(@*Great, I got here - message ID 1289252") in your updatedTransactions (i.e. between lines 20 and 21) to confirm that it is never called.

func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
        if success == true{
        let alert = UIAlertController(title: "Completed", message:"All your previous purchases have been restored", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in })
        let rootVC = UIApplication.shared.keyWindow?.rootViewController
        rootVC?.present(alert, animated: true){}
        }
    }
   
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        print("great, I got here")
            for transaction: AnyObject in transactions {
            let trans = transaction as! SKPaymentTransaction
            switch trans.transactionState {
            case .purchased, .restored:
                let prodID = p.productIdentifier
                switch prodID {
                case "com.Carawind.FlipFlop.RemoveAds":
                    success = true
                    print("got here, too")
                    AdBtn = true
                    UserDefaults.standard.set(true, forKey: "RemovedAds")
                    RemoveAdsBtn.removeFromParent()
                    self.viewController.HideAds()
                default: break
                  
                }
                queue.finishTransaction(trans)
            case .failed:
                print("error")
                success = false
                let alert = UIAlertController(title: "Error", message:"Something went wrong. Try again later", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in })
                let rootVC = UIApplication.shared.keyWindow?.rootViewController
                rootVC?.present(alert, animated: true){}
                queue.finishTransaction(trans)
                break
           
            default:
                break
               
            }
           
           
        }
    }



I update the code you gave me, and I've made sure the sandbox account that I am using have bought the in-app purchase that I am trying to restore. The only thing that happens is it prints out "great, I got here". I can purchase the in-app purchase no problem, but for me its restoring purchases thats the problem. Any ideas?

Ok next baby steps in debugging, but you knew this......

1) Print out the value of trans.transactionState

2) add some more "Got to here!!!" statements to see if you are getting where you expect to get.


You do this to discover the command that ois not operating the way you expect it to. For example, "case .purchased, .restored:" - does that really mean "or"? You can test that by adding that "Got to here!!!" NSLog.

code not working :/
 
 
Q