5

I am developing an application which will allow user to purchase new levels/functionalities using In App Purchase. As far as I know based on my research that I can fetch the In App Purchase products from iTunesConnect using SKProductsRequest by passing a set of ProductIds. And then I have to check whether the user have already purchased any of the products and handle the UI accordingly. I am storing the purchased product Id in NSUderDefaults and the checking them against the returned products. Am not so sure about this procedure because user might plan to delete and reinstall the app at some stage and we'll lose NSUserDefaults and thus user's purchase history.

Is there any way we can fetch user's information from apple server? Or do I have to keep a record of user's purchases on my end.

Thanks in advance

P.S. I followed this tutorial

Manish Ahuja
  • 4,509
  • 3
  • 28
  • 35
  • "- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions" is supposed to return SKPaymentTransactionStateRestored when an item is restored, and you can use "originalTransaction" property to get information about the previous purchase, but I'm not sure this is returned correctly. I read here "http://stackoverflow.com/questions/6806766/skpaymenttransactionstaterestored-doesnt-get-called-when-in-app-purchase-is-bei" that it's not returned – Basel Apr 03 '12 at 12:36
  • If you depend on fetching information, you limit your app's usage by requiring a network connection. If you find some way to record the ownership, then the user can work while "off the grid" (away from a network connection to the internet). – Basil Bourque Mar 07 '14 at 21:36

1 Answers1

5

You can get an array contain all product id's that user already buy it like this .. even if the user uninstall/reinstall your app

- (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];
  }

}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Malek_Jundi
  • 6,140
  • 2
  • 27
  • 36
  • Thanks, I'll test and let you know if it works. And will definitely upvote your answer and set as selected – Manish Ahuja Apr 03 '12 at 16:37
  • Just one question... if I can validate that the user purchased my product this way (by asking apple's servers), why do they recommend for us to keep the receipt? I store the receipt in the user's keychain, retrieve it on launch and then validate the receipt through a validation server. So, an internet connection is required in both cases. Is there a downside to restoring the transaction each time compared to receipt/validation server method? – Sean Oct 16 '20 at 20:24