4

I am using RMStore library to work with auto-renewable subscriptions in my iOS app. It works well for purchasing, but I can't find any documentation how to check with RMStore that current subscription is still active?

Code for checking purchased products does not worked here:

 if([persistence isPurchasedProductOfIdentifier:SUBSCRIPTION_1]) { ... }

This code is always show that Subscription was purchased (because it was) but does not check that this subscription already passed by date.

I see method "isActiveAutoRenewableSubscriptionForDate" in RMAppReceipe.h file, but I does not find any documentation how to retrive subscription receipe in my app with RMStore and how to check this receipe with isActiveAutoRenewableSubscriptionForDate method. Please help.

Summary: I just need to check that subscription @"com.fanfun.apptestsubscription1" is still active for TODAY (current date) or not. Please provide sample code for this simple check.

Dmitry
  • 499
  • 1
  • 3
  • 19

2 Answers2

7

I think I found a solution and it work:

RMAppReceipt* appReceipt = [RMAppReceipt bundleReceipt];

NSLog(@"Is subscription 1 active: %d", [appReceipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:SUBSCRIPTION_1 forDate:[NSDate date]]);
Dmitry
  • 499
  • 1
  • 3
  • 19
  • 1
    Bear in mind that `bundleReceipt` might return nil if the receipt is not available. If so, you will need to refresh the receipt first (via `refreshReceipt` in RMStore). – hpique Jan 18 '14 at 08:38
  • 1
    @hpique What is the best way to refresh it? In my app I have to check for active subscription when user enters certain screen. If subscription is active user gains some benefits, like ad block. I could check for nil receipt every time I'm looking for active subscriptions, and, if check fails, ask user to refresh it before asking for AppleID password. But the downside is that this dialog would appear for each user when he visits this screen for the first time. Are there any best practices regarding receipt refreshing to minimize unpleasant alerts? – Spail Sep 13 '14 at 16:35
  • @Spail did you figure out the best wat to refresh it? – JERC Aug 11 '16 at 15:27
1

I don't know if that library that you use. But if you have access to the receipt itself, You can base64 decode the receipt to get the duration of the receipt in the field "expires-date".

Check those links as well:

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW2

and

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html

UPDATE

[RMAppReceipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:identifier forDate:date]

should do the trick

Denis
  • 165
  • 1
  • 1
  • 12
  • How I can access to receipt with in-app purchases? – Dmitry Jan 16 '14 at 14:14
  • RMStore already have methods to validate receipes (it parse recipes with OpenSSL), I want use it. I can't write my own methods to parse receipes, this is too hard for me. – Dmitry Jan 16 '14 at 14:17
  • 1
    Actually looking at the source of RMStore Library, there is a class called RMAppReceipt (https://github.com/robotmedia/RMStore/blob/master/RMStore/Optional/RMAppReceipt.h). This class has a property "subscriptionExpirationDate" (ln 152). Now the question remains how to get the RMApp Receipt... – Denis Jan 16 '14 at 14:20
  • @Denis This update save my life! I spent hours on figuring this out...Shame it's not on the library doc. – Idan Sep 02 '15 at 00:16