My sandbox test account can purchase non-consumable item and restore it. Everything works. However, if the account have not purchased the item before, pressing the restore button does nothing. I see nothing in the debug panel. I'm expecting iOS to detect if a certain user has purchased the item or not, if not then display a message asking them to buy it. Does it work like that or the current behavior is totally acceptable?
Here is the restore purchase code (Swift) connecting to a button inside the main storyboard:
@IBAction func restoreButtonPressed(sender: UIButton) {
statusLabel.text = "Status: Restoring Purchase"
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}
Other implemented methods include:
Works for normal purchase
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {}
Works for normal restore
func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) {}
Never see messages coming from this method before
func paymentQueue(queue: SKPaymentQueue!, restoreCompletedTransactionsFailedWithError error: NSError!) {}
Thanks!
Restoring purchases prevents you from losing all the things that have been purchased on the old devices. All you need to do is sign in with your old Apple ID or Google Account credentials and you would have restored your purchases. Pretty simple, correct? This menu is available on the side menu of your app.
You can redownload items purchased from the App Store, Book Store, Apple TV app, and iTunes Store without repurchasing them. If you're part of a Family Sharing group, you can download items purchased by other family members, too.
"Restore Purchases" reinstates purchases that haven't been automatically restored, eg. if you are transferring data to a new device. It's not a way to refund your purchases. That needs to go through the store (Apple or GooglePlay).
The "Restore Special Purchases" option allows a new game to restore dresses, bags and other special App Store purchases - items other than in-game currency - to be replaced.
You can check if the queue has any returned transactions, and if not it means that there are no purchases to restore:
func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) {
if queue.transactions.count == 0 {
let alert = UIAlertView()
alert.title = "Oops"
alert.message = "There are no purchases to restore, please buy one"
alert.addButtonWithTitle("Buy")
alert.addButtonWithTitle("Cancel")
alert.show()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With