launchIfNeededWithOptions
Launch the paywall activity conditionally with the specified options.
The paywall will be displayed based on one of these conditions (exactly one must be set):
PaywallActivityLaunchIfNeededOptions.requiredEntitlementIdentifier: Only show if user doesn't have this entitlement
PaywallActivityLaunchIfNeededOptions.shouldDisplayBlock: Only show if this block returns true
Example with entitlement check:
val options = PaywallActivityLaunchIfNeededOptions.Builder()
.setRequiredEntitlementIdentifier("premium")
.setCustomVariables(mapOf("user_name" to CustomVariableValue.String("John")))
.setPaywallDisplayCallback(object : PaywallDisplayCallback {
override fun onPaywallDisplayResult(wasDisplayed: Boolean) {
// Handle result
}
})
.build()
launcher.launchIfNeededWithOptions(options)Content copied to clipboard
Example with custom condition:
val options = PaywallActivityLaunchIfNeededOptions.Builder()
.setShouldDisplayBlock { customerInfo ->
customerInfo.entitlements.active.isEmpty()
}
.setCustomVariables(mapOf("user_name" to CustomVariableValue.String("John")))
.build()
launcher.launchIfNeededWithOptions(options)Content copied to clipboard
Parameters
options
The launch options configured via PaywallActivityLaunchIfNeededOptions.Builder. Must have either PaywallActivityLaunchIfNeededOptions.Builder.setRequiredEntitlementIdentifier or PaywallActivityLaunchIfNeededOptions.Builder.setShouldDisplayBlock set.