Search code examples
iphoneobjective-cxcodecocoa-touchstorekit

Obj-C, Storekit restoreCompletedTransactions returns zero transactions?


I'm having some problems restoring completed transactions.

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

I've added the observer mentioned in several examples, I've tried adding paymentQueueRestoreCompletedTransactionsFinished and already have updatedTransactions. paymentQueueRestoreCompletedTransactionsFinished says I have zero transactions.

I can buy a product and if I try to buy again, it stops me and says I've already bought the product, using this code.

SKPayment *payment = [SKPayment paymentWithProductIdentifier:productIdentifier];
[[SKPaymentQueue defaultQueue] addPayment:payment];

I thought maybe I had a problem with my bundle identifier, but that seems fine and the buy wouldn't work if it wasn't.

I have been trying this on the device as well as the simulator, but this has the same result. Also, it doesn't make a difference If I'm using UK or US store.

I'm really grasping at straws to find out why this doesn't work for me ?


Solution

  • try to do it like this and check the array count is it return zero also ?

    - (void) checkPurchasedItems
    {
       [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
    }//You Call This Function
    
    //Then this delegate Function Will be fired
    - (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
    {
      purchasedItemIDs = [[NSMutableArray alloc] init];
    
      NSLog(@"received restored transactions: %i", queue.transactions.count);
      for (SKPaymentTransaction *transaction in queue.transactions)
      {
          NSString *productID = transaction.payment.productIdentifier;
          [purchasedItemIDs addObject:productID];
      }
    }