Skip to main content
Solved

Delegate vs checking Purchases.shared.getCustomerInfo

  • December 24, 2024
  • 3 replies
  • 40 views

Forum|alt.badge.img

What is the difference between using a delegate (used in the Magic Weather sample app), vs calling Purchases.shared.getCustomerInfo or Purchases.shared.customerInfo() as shown here?

 

Should you use both at the same time, or only one per project?

Best answer by joan-cardona

Hi ​@R1J2,

It depends on your needs, the delegate will be triggered when there’s a change and it will call a certain function where you can perform some action if you need it. Reading it from the singleton shared.customerInfo() will allow you to read data when you request it and perform an action at that moment.

Let me know if that helps!

View original
Did this post help you find an answer to your question?
This post has been closed for comments

joan-cardona
RevenueCat Staff
Forum|alt.badge.img+6

Hi ​@R1J2,

It depends on your needs, the delegate will be triggered when there’s a change and it will call a certain function where you can perform some action if you need it. Reading it from the singleton shared.customerInfo() will allow you to read data when you request it and perform an action at that moment.

Let me know if that helps!


Forum|alt.badge.img
  • New Member
  • January 3, 2025

Thanks ​@joan-cardona!

 

I’d like some clarification on the delegate handler. In the SwiftUI version of the Magic Weather app, I see this comment in the file “PurchasesDelegateHandler”:

 

CustomerInfo is not pushed to each Purchases client, it has to be fetched.

     This delegate method is only called when the SDK updates its cache after an app launch, purchase, restore, or fetch.

     You still need to call `Purchases.shared.customerInfo` to fetch CustomerInfo regularly.

 

Does this mean that the SDK will actively fetch customerInfo every time the app is launched, and therefore detects if there is a change the customer entitlement? 

 

Is using the delegate method alone sufficient in detecting when a customer’s subscription has expired and therefore deny access to paid features?

 

Or should I absolutely call Purchases.shared.customerInfo manually?

 

New RevenueCat user and iOS developer, so just making sure I am understanding the inside workings correctly!


joan-cardona
RevenueCat Staff
Forum|alt.badge.img+6

Hi ​@R1J2,

The SDK automatically fetches the Customer Info every 5 minutes approximately. You can listen to the delegate to get notified as soon as the customer info changes or you can just fetch it when you need it. I would recommend you doing it this way, since we store in cache the data it’s safe to call it when you need it and it’ll be available immediately. The most normal scenario is to get Purchases.shared.customerInfo when the user tries to access a premium feature, if you don’t see the active entitlement you can show the paywall. For this case, you don’t need to be listening to the delegate continuously.

Let me know if that helps! 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings