iphone - IAP Restoration -


i got problem working on restoration of purchased product. every time user clicks on restore button unlock content works before checking if user logged in, had purchased or not. unlocks. here question: how right? add code restoration function , purchase one. btw purchasing works perfect.

 func restorepurchases(){       println("hello")       skpaymentqueue.defaultqueue().addtransactionobserver(self)       skpaymentqueue.defaultqueue().restorecompletedtransactions()  }   func buyproduct(){       skpaymentqueue.defaultqueue().addtransactionobserver(self)       let payment:skpayment = skpayment(product: product)       skpaymentqueue.defaultqueue().addpayment(payment)  }   func paymentqueue(queue: skpaymentqueue!, restorecompletedtransactionsfailedwitherror error: nserror!) {       showalert("error", message: "hoho")  }   func paymentqueue(queue: skpaymentqueue!, updatedtransactions transactions: [anyobject]!) {       transaction:anyobject in transactions {            if let trans:skpaymenttransaction = transaction as? skpaymenttransaction{                 switch trans.transactionstate{                 case .purchased:                      self.removeads()                      skpaymentqueue.defaultqueue().finishtransaction(transaction as! skpaymenttransaction)                      break                 case .failed:                      showalert("error", message: "transaction problem")                      skpaymentqueue.defaultqueue().finishtransaction(transaction as! skpaymenttransaction)                      break                 case .restored:                      self.removeads()                      break                 default:                      break                 }            }       }  } 

i got answer! main problem didnt finish transaction in .restored, got same thing .purchased , .restored.

     func paymentqueue(queue: skpaymentqueue!, updatedtransactions transactions: [anyobject]!) {       transaction:anyobject in transactions {            if let trans:skpaymenttransaction = transaction as? skpaymenttransaction{                 switch trans.transactionstate{                 case .purchased, .restored:                      self.removeads()                      skpaymentqueue.defaultqueue().finishtransaction(transaction as! skpaymenttransaction)                      break                 case .failed:                      showalert("error", message: "transaction problem")                      skpaymentqueue.defaultqueue().finishtransaction(transaction as! skpaymenttransaction)                      break                 default:                      break                 }            }       }  } 

next - didnt check can customer make purchases or not. before made observer:

     func restorepurchases(){       skpaymentqueue.defaultqueue().addtransactionobserver(self)       if skpaymentqueue.canmakepayments(){            skpaymentqueue.defaultqueue().restorecompletedtransactions()       }  } 

so, easy :d everyone!


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -