Skip to main content

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?

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!


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!


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!