Display flows & paywalls - Unity
If you’ve created a flow, or a paywall in the old Paywall Builder, you don’t need to worry about rendering it in your mobile app code to display it to the user. Such a flow or paywall contains both what should be shown within it and how it should be shown.
This guide covers flows and paywalls rendered by Adapty. The process differs for custom paywalls and Observer mode.
- To present custom paywalls, see Present custom paywalls.
- For presenting flows in Observer mode, see Present flows in Observer mode.
To get the view object used below, see Get flows & paywalls.
To display a flow or paywall, use the view.Present() method on the view created by the CreateFlowView method. By default, a dismissed view is destroyed. To display the flow again, call CreateFlowView one more time to create a new view instance, or keep the view when you dismiss it.
Reusing a destroyed view results in an error.
view.Present((error) => {
// handle the error
});Want to see a real-world example of how Adapty SDK is integrated into a mobile app? Check out our sample apps, which demonstrate the full setup, including displaying paywalls, making purchases, and other basic functionality.
Keep the view to present it again
Kept views are available starting from SDK version 4.3.0.
view.Dismiss() releases the view from memory. To keep the view instead, pass false as the destroy parameter:
view.Dismiss(false, (error) => {
// handle the error
});Present that view again and the user returns to the screen they left, with the state the flow had built up. The view keeps its Id, so its events still arrive in your listener with the same view.Id.
A kept view stays in memory until you release it. When you no longer need it, call view.Destroy():
view.Destroy((error) => {
// handle the error
});Destroy() dismisses the view first if it’s still on screen. It also releases a view that you created but never presented, and a page-sheet view that the user swiped down on iOS. Don’t call it after a regular Dismiss(): that view is already released, and the call fails.
To keep a view when the user taps a Close button, dismiss it with destroy: false in your Close action handler. The FlowViewDidPerformAction method runs for every flow and paywall in your app, so compare view.Id to keep only the view you plan to present again. Store the view in a field when you create it, so you can compare against it and present it later:
private AdaptyUIFlowView keptView;
void CreateKeptView(AdaptyFlow flow) {
AdaptyUI.CreateFlowView(flow, new AdaptyUICreateFlowViewParameters(), (view, error) => {
if (error != null) {
// handle the error
return;
}
keptView = view;
});
}
public void FlowViewDidPerformAction(
AdaptyUIFlowView view,
AdaptyUIUserAction action
) {
switch (action.Type) {
case AdaptyUIUserActionType.Close:
view.Dismiss(view.Id != keptView?.Id, null);
break;
default:
// handle other events
break;
}
}Hold on to the kept view: you need it to present the flow or paywall again, and to release it with Destroy(). After you call keptView.Destroy(), set keptView to null, so the comparison above doesn’t match a released view. Any other view.Dismiss() call releases the view too, including the call in FlowViewDidReceiveError. After a view error, create a new view with CreateFlowView.
Show dialog
Use this method instead of native alert dialogs when a flow or paywall is presented on Android. On Android, regular alerts appear behind the flow view, which makes them invisible to users. This method ensures proper dialog presentation above the flow on all platforms.
var dialog = new AdaptyUIDialogConfiguration()
.SetTitle("Close this screen?")
.SetContent("You will lose access to exclusive offers.")
.SetDefaultActionTitle("Stay")
.SetSecondaryActionTitle("Close");
AdaptyUI.ShowDialog(view, dialog, (action, error) => {
if (error == null) {
if (action == AdaptyUIDialogActionType.Secondary) {
// User confirmed - close the flow
view.Dismiss((error) => {
// handle the error
});
}
// If primary - do nothing, user stays
}
});Configure iOS presentation style
Configure how the flow or paywall is presented on iOS by passing the iosPresentationStyle parameter to the Present() method. The parameter accepts AdaptyUIIOSPresentationStyle.FullScreen (default) or AdaptyUIIOSPresentationStyle.PageSheet values.
view.Present(AdaptyUIIOSPresentationStyle.PageSheet, (error) => {
// handle the error
});The user can swipe a page sheet down to close it. The view then stays in memory without a Dismiss() call: present it again, or, on SDK 4.3.0 and later, release it with Destroy().
If you’ve customized a paywall using the Paywall Builder, you don’t need to worry about rendering it in your mobile app code to display it to the user. Such a paywall contains both what should be shown within the paywall and how it should be shown.
This guide covers the old Paywall Builder, which requires Adapty SDK 3.3.0 or later.
To present custom paywalls, see Present custom paywalls.
To display a paywall, use the view.Present() method on the view created by the CreatePaywallView method. Each view can only be used once. If you need to display the paywall again, call CreatePaywallView one more to create a new view instance.
Reusing the same view without recreating it may result in an AdaptyUIError.viewAlreadyPresented error.
view.Present((error) => {
// handle the error
});Want to see a real-world example of how Adapty SDK is integrated into a mobile app? Check out our sample apps, which demonstrate the full setup, including displaying paywalls, making purchases, and other basic functionality.
Show dialog
Use this method instead of native alert dialogs when a paywall view is presented on Android. On Android, regular alerts appear behind the paywall view, which makes them invisible to users. This method ensures proper dialog presentation above the paywall on all platforms.
var dialog = new AdaptyUIDialogConfiguration()
.SetTitle("Close paywall?")
.SetContent("You will lose access to exclusive offers.")
.SetDefaultActionTitle("Stay")
.SetSecondaryActionTitle("Close");
AdaptyUI.ShowDialog(view, dialog, (action, error) => {
if (error == null) {
if (action == AdaptyUIDialogActionType.Secondary) {
// User confirmed - close the paywall
view.Dismiss();
}
// If primary - do nothing, user stays
}
});Configure iOS presentation style
Configure how the paywall is presented on iOS by passing the iosPresentationStyle parameter to the Present() method. The parameter accepts AdaptyUIIOSPresentationStyle.FullScreen (default) or AdaptyUIIOSPresentationStyle.PageSheet values.
view.Present(AdaptyUIIOSPresentationStyle.PageSheet, (error) => {
// handle the error
});