3
votes

My app was rejected for not implementing "Restore Purchases" feature.

Apple says

We found that your app offers In-App Purchase/s that can be restored but it does not include a "Restore" feature to allow users to restore the previously purchased In-App Purchase/s. To restore previously purchased In-App Purchase products, it would be appropriate to provide a "Restore" button and initiate the restore process when the "Restore" button is tapped.

So I finally decided to add that and I found we have to use

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

But it doesn't help! I searched for similar questions but found none working for my app. These are the following links that I have stacked so far :

Restore already bought in-app-purchases on iPhone?

iOS6 - In app purchase with download from Apple server

Please help!! Thanks in advance..

2
btw you'll need a visible "Restore button", not just code to automatically restoreJake Crastly
yes that I have added !!Jen Jose

2 Answers

3
votes

Try the following :

On Restore button click -->

- (IBAction)retoreinApp:(id)sender
{
    //set  addTransactionObserver to self. 
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

}

This will call

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

    UIAlertView *alert ;
    if(queue.transactions.count >0)
    {
        for (SKPaymentTransaction *transaction in queue.transactions)
        {
            NSString *productId = transaction.payment.productIdentifier;

          NSLog(@" ProductIdentifier is %@",productId);
            if([productId isEqualToString:@"com.xy.yourProductId"])
            {//add code to add it to your account
             }
          alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"All your previous transactions are restored successfully." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

  }
    else
    {
        alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"No transactions in your account to be restored." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    }
    [alert show];

}
0
votes

Update @user4936766's answer to Swift 5

import StoreKit

class ViewController: UIViewController {

    @IBAction func retoreinApp(_ sender: UIButton) {

        SKPaymentQueue.default().add(self)
        SKPaymentQueue.default().restoreCompletedTransactions()
    }
}

extension ViewController: SKPaymentTransactionObserver{

    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { }

    func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) { }

    func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
        var alert: UIAlertController!
        if(queue.transactions.count > 0){
            for transaction in queue.transactions{
                 let productId = transaction.payment.productIdentifier
                 print(" ProductIdentifier is \(productId)")
                 if productId == "com.xy.yourProductId"{
                    //add code to add it to your account
                 }
            }
            alert = UIAlertController(title: "Restore Transactions", message: "All your previous transactions are restored successfully.", preferredStyle: UIAlertController.Style.alert)
         }
         else{
            alert = UIAlertController(title: "Restore Transactions", message: "No transactions in your account to be restored.", preferredStyle: UIAlertController.Style.alert)
         }
         let cancel = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil)
         alert.addAction(cancel)
         present(alert, animated: true){}
    }
}

A "Restore Purchase" button style in a Chinese Video Play App iQiYi.

demo