Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-App Purchases Restore

I'm trying to do in-app purchases and everything works fine except Restore. Below is the code I have written:

func paymentQueueRestoreCompletedTransactionsFinished(queue:SKPaymentQueue!)
{
    for transaction:AnyObject in queue.transactions
    {
        let trans : SKPaymentTransaction = transaction as SKPaymentTransaction
        var identifier : NSString = trans.payment.productIdentifier
        println(identifier)
    }
}

The problem that I face here is I'm not getting the purchased identifier here. I think I have miswritten the code.

like image 715
Riyazul Aboobucker Avatar asked Nov 11 '14 05:11

Riyazul Aboobucker


People also ask

What does restore mean for in-app purchases?

Answer: A: Answer: A: It means that if you made an in-app purchase in that game but on another device you can restore those purchases with your apple ID log in credentials without having to pay again.

Why are my in-app purchases not working?

If you haven't received an in-app item you bought, try closing and restarting the app or game you're using. Tap Apps or Manage applications (depending on your device, this may be different). Tap the app you used to make your in-app purchase.


2 Answers

Riyazul, you need to look at the original transaction when you are restoring purchases.

The code you should need is:

var identifier : NSString = trans.originalTransaction.payment.productIdentifier

Let me know if it's still not working.

like image 142
Greenwolf Avatar answered Sep 22 '22 09:09

Greenwolf


Add below two lines of code on your button click action

SKPaymentQueue.default().restoreCompletedTransactions()
SKPaymentQueue.defaultQueue().addTransactionObserver(self)

Edit - for Swift 3:

SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()
like image 36
Bharat Rawal Avatar answered Sep 26 '22 09:09

Bharat Rawal