Question

on app load, can I request the current server status in react native?

  • 23 April 2024
  • 2 replies
  • 12 views

Badge +3

My app retrieve subscription status when the app starts

const customerInfo: CustomerInfo = await Purchases.getCustomerInfo(); console.log('current time', getDateTimeDisplayString(new Date().getTime())); console.log('customer info when loading the app', customerInfo);

however, it always loads the last cached data in my ios simulator

 LOG  current time 2024-04-22 19:35:32
 LOG  customer info when loading the app {"activeSubscriptions": [], "allExpirationDates": {}, "allExpirationDatesMillis": {}, "allPurchaseDates": {}, "allPurchaseDatesMillis": {}, "allPurchasedProductIdentifiers": [], "entitlements": {"active": {}, "all": {}, "verification": "NOT_REQUESTED"}, "firstSeen": "2024-04-22T23:30:56Z", "firstSeenMillis": 1713828656000, "latestExpirationDate": null, "latestExpirationDateMillis": null, "managementURL": null, "nonSubscriptionTransactions": [], "originalAppUserId": "56de1eda-4738-a098-55b8-041900dc5f37", "originalApplicationVersion": null, "originalPurchaseDate": null, "originalPurchaseDateMillis": null, "requestDate": "2024-04-22T23:32:07Z", "requestDateMillis": 1713828727000}

 

If I request the customer info later in the app. it returns the correct data. 

 LOG  current time 2024-04-22 19:35:54
 LOG  customer info when requested later  {"activeSubscriptions": ["rc_promo_Standard_daily"], "allExpirationDates": {"rc_promo_Standard_daily": "2024-04-23T23:32:40Z"}, "allExpirationDatesMillis": {"rc_promo_Standard_daily": 1713915160000}, "allPurchaseDates": {"rc_promo_Standard_daily": "2024-04-22T23:32:40Z"}, "allPurchaseDatesMillis": {"rc_promo_Standard_daily": 1713828760000}, "allPurchasedProductIdentifiers": ["rc_promo_Standard_daily"], "entitlements": {"active": {"Standard": [Object]}, "all": {"Standard": [Object]}, "verification": "NOT_REQUESTED"}, "firstSeen": "2024-04-22T23:30:56Z", "firstSeenMillis": 1713828656000, "latestExpirationDate": "2024-04-23T23:32:40Z", "latestExpirationDateMillis": 1713915160000, "managementURL": null, "nonSubscriptionTransactions": [], "originalAppUserId": "xxx", "originalApplicationVersion": null, "originalPurchaseDate": null, "originalPurchaseDateMillis": null, "requestDate": "2024-04-22T23:35:32Z", "requestDateMillis": 1713828932000}

 

Is there a way when app loads always request the latest server status? I saw other post saying I should wait a few seconds to request customer info, should I do that instead? Wondering how everyone handles it, 

 

thanks, 

 

Lin
 

 


This post has been closed for comments

2 replies

Userlevel 1
Badge +3

Hi @lin-song-dc538f!

CustomerInfo implements a cache policy to reduce reliance on the network (details here). Fresh CustomerInfo should be fetched when Purchases is configured - I'm curious if you're awaiting your call to Purchases.configure()?

We generally recommend setting up platform server notifications and the customerInfo listener for faster updates. Also, it's common practice (and safe) to call getCustomerInfo whenever your users need to access premium content (or when your UI needs to show subscription status). So feel free to call this method liberally throughout your app's lifecycle.

Please let me know if you have additional questions.

Thanks!

Badge +3

Hi Jeffrey, 

Thanks for the reply! 

Purchases.configure is not an async function,  so I cannot do await.  

My suspicions is after the configure is done,  the network call to update the cache need a bit of time after app starts. If I immediately ask for customerInfo,  it is the cache.   My temporary workaround is to wait 2 seconds and by then the cache is updated. 

Since my app allows user to access w/ or w/o a subscription ( more advanced features),  once user opens the app,  I want to show if user has a subscription or not to remind them to subscribe. Also there is no login, thus the issue is kind of unique to my app.   Ideally,  I hope there is a way to explicit ask for the server copy upon app load or at least there is timestamp on when the cache is updated.  

Lin