Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In app purchase - Storing/fetching user purchase history | iOS

Tags:

xcode

iphone

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

like image 660
Manish Ahuja Avatar asked Apr 03 '12 11:04

Manish Ahuja


People also ask

Does the app store have a purchase history?

Authenticate your Apple ID, then click View Account. On the Account Information page, scroll to Purchase History. To the right of Most Recent Purchase, click See All. It might take a moment for your Purchase History to appear.


1 Answers

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

}
like image 162
Malek_Jundi Avatar answered Oct 12 '22 01:10

Malek_Jundi