Tracking Subscription State
Here’s how to view whether or not a user is on a paid plan or not.
In your app’s models, you might wish to set a flag representing whether or not a user is on a paid subscription:
Using subscription status
You can do this by observing the subscriptionStatus
property on Superwall.shared
. This property is an enum that represents the user’s subscription status:
One natural way to tie the logic of your model together with Superwall’s subscription status is by having your own model conform to the Superwall Delegate:
Another shorthand way to check? The isActive
flag, which returns true if any entitlement is active:
Listening for entitlement changes in SwiftUI
For Swift based apps, you can also create a flexible custom modifier which would fire if any changes to a subscription state occur. Here’s how:
Superwall checks subscription status for you
Remember that the Superwall SDK uses its audience filters for a similar purpose. You generally don’t need to wrap your calls registering placements around if
statements checking if a user is on a paid plan, like this:
In your audience filters, you can specify whether or not the subscription state should be considered…
…which eliminates the needs for code like the above. This keeps you code base cleaner, and the responsibility of “Should this paywall show” within the Superwall campaign platform as it was designed.