0

I am implementing in app purchases for my iOS application. Apple has rejected my binary for not restoring purchased products. In my application once the user taps the icon of product if item is locked he/she directed to inApp purchase process else the products gets openend. There is no visual Buy button. Now apple is saying to provide the restore button? Can anybody tell me how to handle this? I have tried

- (void) checkPurchasedItems
{
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}// Call This Function

//Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    alreadyPurchasedItems = [[NSMutableArray alloc] init];

    NSLog(@"received restored transactions: %i", queue.transactions.count);
    for (SKPaymentTransaction *transaction in queue.transactions)
    {
        NSString *ID = transaction.payment.productIdentifier;
        [alreadyPurchasedItems addObject:ID];
    }

}

On application launch but paymentQueueRestoreCompletedTransactionsFinished method is never called so that I can get the list of already purchased items and then directly inform user if he/she purchased this already.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Awais Tariq
  • 7,724
  • 5
  • 31
  • 54

1 Answers1

3

How do you set the delegate of [SKPaymentQueue defaultQueue]? I guess you already do smt like:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

After that [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; should result in below method to be fired. So the case SKPaymentTransactionStateRestored is where you implement it:

-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction * transaction in transactions) {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:                
                ...
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:                
                ...
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:                
                ...
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            default:
                break;
        }
    };
}

You may have a look at this tutorial, restoration is explained in more detail towards the very end of it. http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial

guenis
  • 2,520
  • 2
  • 25
  • 37