2

I am implementing Auto-renewable InApp Purchase for iOS. It is working fine for first month. But I am unable to know whether user's subscription is auto renewed or not means what is the status of current InApp Purchase.

After studying so many answers on StackOverflow, I am able to understand that I have to provide Restore button to Restore transaction. I have implemented it as well and it is giving my all transactions till date. So, I am unable to get my last transaction. So, please help to understand the status of last auto renewed transaction so that I shall be able to update the status on my server.

Below is the code I am using to restore my transaction:

 [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];

and implementing its delegates as follows:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
NSLog(@"%@",queue );
NSLog(@"Restored Transactions are once again in Queue for purchasing %@",[queue transactions]);

NSMutableArray *purchasedItemIDs = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %zd", queue.transactions.count);

for (SKPaymentTransaction *transaction in queue.transactions)
{
    NSString *productID = transaction.payment.productIdentifier;
    [purchasedItemIDs addObject:productID];
    NSLog (@"product id is %@" , productID.description);
    NSLog (@"observationInfo is %@" , transaction.payment.productIdentifier.observationInfo);


    // here put an if/then statement to write files based on previously purchased items
    // example if ([productID isEqualToString: @"youruniqueproductidentifier]){write files} else { nslog sorry}
}
 }


- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
  {
    NSLog(@"Restore Error... %@",error.description);
   }
Mohit Tomar
  • 5,173
  • 2
  • 33
  • 40
Ankit Goyal
  • 3,019
  • 1
  • 21
  • 26

1 Answers1

0

I guess transaction restore is not work if application is running and Transaction is renew. Please refer StoreKit Guide :-

After a subscription is successfully renewed, Store Kit adds a transaction for the renewal to the transaction queue. Your app checks the transaction queue on launch and handles the renewal the same way as any other transaction. Note that if your app is already running when the subscription renews, the transaction observer is not called; your app finds out about the renewal the next time it’s launched.

After relaunch application, Transaction restore functionality work fine with restoring current auto-renewed transaction.

On Alternate, If you want to check transaction is renewed or not without relaunch application, You can do with manually refreshing "App Receipt".

Link (Expiration and Renewal) :- https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Subscriptions.html

Sagar Thummar
  • 2,034
  • 15
  • 21