Skip to main content
Answer

Whats the Best way to listen to an active Subscription

  • May 31, 2023
  • 3 replies
  • 144 views

Forum|alt.badge.img+3

Hey RC community 

could someone please tell me the very Best way to check for an active subscription ?

My Current implementation is 

customerInfo.entitlements.active.isNotEmpty

at One Point my implementation was  listening to the expiration date

customerInfo.latestExpirationDate.

then  added 3 Days to it , which would give the user at least 3 days to have premium service, should in case there’s subscription verification delay from RC database, I implemented this because I have noticed that sometimes when I Hot Restart my App, 1 out of 50 times it loses Subscription and then it regain after another hot restart  , this mostly happened when its time for the Sandbox to renew the subscription, by adding a Day or more to the current subscription latestExpirationDate. it give a lot of room for the server to correct itself and not make customer lose premium service.

I don't know if this behavior only exist in debug mode.

 

could someone please tell me, if I should be be worried about this in production .

 i’m just a day or two from submitting my project for review 

 

Regard!

Best answer by Michael Fogel

Hello! 

 

The simplest way to check if a subscription is active or not would be checking if your entitlement offered isActive or not by checking the customerInfo object. A code example of this can be found here

if customerInfo.entitlements[<your_entitlement_id>]?.isActive == true {
// user has access to "your_entitlement_id"
}

 

Your current implementation seems close to the one that i referenced above, and that should return the entitlement being active when it is active. As for your sandbox bug, We dont normally see that in production but I would recommend checking against if the entitlement is active or not and keeping it simpler just in case! 

This post has been closed for comments

3 replies

Michael Fogel
Forum|alt.badge.img+6
  • Dedicated Contributor
  • Answer
  • June 1, 2023

Hello! 

 

The simplest way to check if a subscription is active or not would be checking if your entitlement offered isActive or not by checking the customerInfo object. A code example of this can be found here

if customerInfo.entitlements[<your_entitlement_id>]?.isActive == true {
// user has access to "your_entitlement_id"
}

 

Your current implementation seems close to the one that i referenced above, and that should return the entitlement being active when it is active. As for your sandbox bug, We dont normally see that in production but I would recommend checking against if the entitlement is active or not and keeping it simpler just in case! 


Forum|alt.badge.img+3
  • Author
  • New Member
  • June 2, 2023

Thanks Chief!


Michael Fogel
Forum|alt.badge.img+6
  • Dedicated Contributor
  • June 5, 2023

No problem, glad I could help!