Skip to main content
Question

Not receiving PurchasesDelegate callback when user cancels free trial plan


Forum|alt.badge.img+5

By using the following code, I can receive PurchasesDelegate callback, when user subscribes to a free trial plan.

However, I am not able to receive PurchasesDelegate callback, when user cancels the free trial plan.

class AppDelegate: UIResponder, UIApplicationDelegate {

    // https://www.revenuecat.com/docs/integrations/attribution/apple-search-ads
    // https://www.revenuecat.com/docs/integrations/attribution/facebook-ads#3-send-revenuecat-events-into-facebook-ads-manager
    private func initRevenueCat() {
        Purchases.configure(with:
            .init(withAPIKey: "appl_???")
            .with(
                purchasesAreCompletedBy: .myApp,
                storeKitVersion: .storeKit2
            )
        )

        Purchases.shared.attribution.enableAdServicesAttributionTokenCollection()

        // Automatically collect the $idfa, $idfv, and $ip values
        Purchases.shared.attribution.collectDeviceIdentifiers()
        // REQUIRED: Set the Facebook anonymous Id
        Purchases.shared.attribution.setFBAnonymousID(FBSDKCoreKit.AppEvents.shared.anonymousID)

        Purchases.shared.delegate = self
    }
}

extension AppDelegate: PurchasesDelegate {
    func purchases(_ purchases: Purchases, receivedUpdated customerInfo: CustomerInfo) {
        // handle any changes to customerInfo
    }
}

May I know how I can fix this? Thanks.

This post has been closed for comments

3 replies

Forum|alt.badge.img+8
  • RevenueCat Staff
  • 509 replies
  • January 31, 2025

Hi, the delegate on the device is only called if new PurchaserInfo is returned that is different than what was fetched previously. e.g. the subscription expiration date changes, active product changes, etc. This could occur by calling purchaserInfo directly, making a purchase, restoring a purchase, etc.
Subscription status changes aren't pushed to the delegate from the RevenueCat server so the auto-renewal turning off for the trial will not trigger the PurchasesDelegate callback.

I recommend listening to RevenueCat webhooks for a cancellation event to be alerted of when a trial’s auto-renewal turns off: https://www.revenuecat.com/docs/integrations/webhooks


Forum|alt.badge.img+5

Hi, currently, we only have a customer facing iOS app, without a server. Hence, we are not able to use webhook.

Can we workaround with this, actively calling

Purchases.shared.syncPurchases

followed by

Purchases.shared.getCustomerInfo

every 24 hours?

Thanks.


Forum|alt.badge.img+8
  • RevenueCat Staff
  • 509 replies
  • February 10, 2025

Instead of Purchases.shared.syncPurchases, I recommend calling invalidateCustomerInfoCache() as this will force the SDK to fetch the data again. See our docs here for how the customerInfo caches

 


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