在 Unity SDK 中展示用户引导

如果您已使用编辑工具自定义了用户引导,则无需担心在 Unity 应用代码中进行渲染即可将其展示给用户。此类用户引导既包含应在其中显示的内容,也包含其展示方式。

开始之前,请确保:

  1. 您已安装 Adapty Unity SDK 3.14.0 或更高版本。
  2. 您已创建用户引导
  3. 您已将用户引导添加到版位中。

要展示用户引导,请对由 CreateOnboardingView 方法创建的 view 调用 view.Present() 方法。每个 view 只能使用一次。如果需要再次展示付费墙,请再次调用 CreateOnboardingView 以创建新的 view 实例。

在未重新创建的情况下复用同一个 view 可能会导致 AdaptyUIError.viewAlreadyPresented 错误。

view.Present((presentError) => {
    if (presentError != null) {
        // handle the error
    }
};

配置 iOS 展示样式

通过将 iosPresentationStyle 参数传递给 Present() 方法,可配置用户引导在 iOS 上的展示方式。该参数接受 AdaptyUIIOSPresentationStyle.FullScreen(默认值)或 AdaptyUIIOSPresentationStyle.PageSheet 值。

view.Present(AdaptyUIIOSPresentationStyle.PageSheet, (error) => {
    // handle the error
});

自定义用户引导中链接的打开方式从 Adapty SDK v. 3.15 开始支持。

默认情况下,用户引导中的链接会在应用内浏览器中打开,通过在应用内直接显示网页而无需切换应用,从而提供无缝体验。

如需改为在外部浏览器中打开链接,请将 AdaptyWebPresentation.ExternalBrowser 传递给 CreateOnboardingView 方法:

AdaptyUI.CreateOnboardingView(
    onboarding,
    AdaptyWebPresentation.ExternalBrowser, // default — InAppBrowser
    (view, error) => {
        if (error != null) {
            // handle the error
            return;
        }

        // present the onboarding view
        view.Present((presentError) => {
            if (presentError != null) {
                // handle the error
            }
        });
    }
);

可用选项:

  • AdaptyWebPresentation.InAppBrowser - 在应用内浏览器中打开链接(默认)
  • AdaptyWebPresentation.ExternalBrowser - 在设备的外部浏览器中打开链接