Solved

Check the subscription when the Device is off-line?

  • 10 August 2021
  • 8 replies
  • 789 views

Userlevel 1
Badge +6

This is the scenario.
I develop with Flutter.
I have a subscription that is automatically renewed monthly or annually.
My app can safely work with all the features even off-line.
Of course, to subscribe, you need to be online.
But I wonder: if after the first monthly subscription, the user always uses my app off-line (he must of course remember to put the device off-line before using it), how can I check if the subscription has been deleted?
Can there be a way?
Thanks for any suggestion.

icon

Best answer by ryan 10 August 2021, 18:01

View original

8 replies

Userlevel 5
Badge +9

You can call the .getPurchaserInfo() method the same way you would as if the device is offline. 

The latest PurchaserInfo object is cached on the device, and will always be returned first. The cache will get updated when a network connection resumes.

What this means for your customers is that the subscription status will remain the same as what it was when the device went offline.

 

how can I check if the subscription has been deleted?

You’ll need a network connection to detect any changes in the subscription that may have occurred while offline. If this is a hard requirement, then you should not allow offline usage of your app.

Userlevel 1
Badge +6

Thanks for the precise explanation.
In my application, being able to be used off-line is a feature that I would like to leave behind because it gives an extra option. However, the problem of detecting whether the subscription is still active is fundamental.
Could you give me some advice on how to solve the problem. Maybe using the property:
purchaserInfo.entitlements.all [entitlementID] ?. expirationDate

Userlevel 5
Badge +9

Unfortunately I can’t think of a way to get a 100% correct subscription status without a network connection.

You could get the expiration date of the entitlement, but you can’t be sure what is supposed to happen after that - detecting a renewal or cancellation would require a network connection. 

Also, the device date is easy to change by dimply changing the date/time on the phone so you shouldn’t do any comparisons to the device `Date()`, only a server timestamp.

Userlevel 1
Badge +6

Thanks.

Userlevel 1
Badge +4

Interesting thread. I was wondering whether the isActive property could be more sophisticated using the data available such as expiration date, and willRenew. Point taken the date on the device could be edited, but for 99% of people editing their device date to get free subscriptions would never be worth the trade off. 

Userlevel 1
Badge +6

I agree with you

Badge +2

I have a similar requirement as Carlo Sacchetti and instead of using purchaserInfo.entitlement.expiryDate I was thinking of using both:

  • purchaserInfo.entitlements[premiumEntitlementID].isActive
  • purchaserInfo.requestDate.

Here is my detailed solution:

I was thinking of checking the purchaserInfo.entitlements[premiumEntitlementID].isActive, by calling Purchases.shared.purchaserInfo() at 2 places:
- when the app becomes active.
- when the app is active and the internet connection becomes actives.

Then anytime a user would access a premium feature, the app would first make sure the premium entitlement is active and purchaserInfo.requestDate is not older than 24h, otherwise I would consider the premium entitlement to be stale and kindly ask the user to go online to keep using the premium features.

Provided the user does not change their phone date, would you consider this to be a workable solution? Is this any better actually than checking on purchaserInfo.entitlement.expiryDate?

Badge +2

You could always unpack the customer info while offline and check against the expiration date.

Reply