处理流程与付费墙事件 - React Native
本指南介绍如何处理购买、恢复、产品选择和流程渲染的事件。你也可以设置按钮处理(关闭流程、打开链接、自定义操作等)。详情请参阅按钮操作处理指南。
流程和付费墙编辑工具构建的流程和付费墙无需额外代码即可完成购买和恢复购买。但它们会生成一些事件,供你的应用响应。这些事件包括按钮点击(关闭按钮、URL、产品选择等)以及流程中与购买相关的操作通知。请参阅以下内容,了解如何响应这些事件。
要在移动应用中控制或监控流程界面上发生的过程,请实现事件处理程序:
对于 React 组件,你可以通过 AdaptyFlowView 组件中各自的事件处理器 props 来处理事件:
function MyFlow({ flow }) {
const onCloseButtonPress = useCallback<FlowEventHandlers['onCloseButtonPress']>(() => {}, []);
const onProductSelected = useCallback<FlowEventHandlers['onProductSelected']>((productId) => {}, []);
const onPurchaseStarted = useCallback<FlowEventHandlers['onPurchaseStarted']>((product) => {}, []);
const onPurchaseCompleted = useCallback<FlowEventHandlers['onPurchaseCompleted']>((purchaseResult, product) => {}, []);
const onPurchaseFailed = useCallback<FlowEventHandlers['onPurchaseFailed']>((error, product) => {}, []);
const onRestoreStarted = useCallback<FlowEventHandlers['onRestoreStarted']>(() => {}, []);
const onRestoreCompleted = useCallback<FlowEventHandlers['onRestoreCompleted']>((profile) => {}, []);
const onRestoreFailed = useCallback<FlowEventHandlers['onRestoreFailed']>((error) => {}, []);
const onAppeared = useCallback<FlowEventHandlers['onAppeared']>((view) => {}, []);
const onError = useCallback<FlowEventHandlers['onError']>((error) => {}, []);
const onLoadingProductsFailed = useCallback<FlowEventHandlers['onLoadingProductsFailed']>((error) => {}, []);
const onUrlPress = useCallback<FlowEventHandlers['onUrlPress']>((url, openIn) => {
adapty.openWebUrl(url, openIn);
return false;
}, []);
const onCustomAction = useCallback<FlowEventHandlers['onCustomAction']>((actionId) => {}, []);
const onWebPaymentNavigationFinished = useCallback<FlowEventHandlers['onWebPaymentNavigationFinished']>(() => {}, []);
return (
<AdaptyFlowView
flow={flow}
style={styles.container}
onCloseButtonPress={onCloseButtonPress}
onProductSelected={onProductSelected}
onPurchaseStarted={onPurchaseStarted}
onPurchaseCompleted={onPurchaseCompleted}
onPurchaseFailed={onPurchaseFailed}
onRestoreStarted={onRestoreStarted}
onRestoreCompleted={onRestoreCompleted}
onRestoreFailed={onRestoreFailed}
onAppeared={onAppeared}
onError={onError}
onLoadingProductsFailed={onLoadingProductsFailed}
onUrlPress={onUrlPress}
onCustomAction={onCustomAction}
onWebPaymentNavigationFinished={onWebPaymentNavigationFinished}
/>
);
}事件示例(点击展开)
// onCloseButtonPress
{
//Record the event
}
// onAndroidSystemBack
{
//Record the event
}
// onUrlPress
{
"url": "https://example.com/terms"
}
// onCustomAction
{
"actionId": "login"
}
// onProductSelected
{
"productId": "premium_monthly"
}
// onPurchaseStarted
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onPurchaseCompleted - Success
{
"purchaseResult": {
"type": "success",
"profile": {
"accessLevels": {
"premium": {
"id": "premium",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
}
}
},
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onPurchaseCompleted - Cancelled
{
"purchaseResult": {
"type": "user_cancelled"
},
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onPurchaseFailed
{
"error": {
"code": "purchase_failed",
"message": "Purchase failed due to insufficient funds",
"details": {
"underlyingError": "Insufficient funds in account"
}
},
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onRestoreCompleted
{
"profile": {
"accessLevels": {
"premium": {
"id": "premium",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
},
"subscriptions": [
{
"vendorProductId": "premium_monthly",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
]
}
}
// onRestoreFailed
{
"error": {
"code": "restore_failed",
"message": "Purchase restoration failed",
"details": {
"underlyingError": "No previous purchases found"
}
}
}
// onError
{
"error": {
"code": "rendering_failed",
"message": "Failed to render flow interface",
"details": {
"underlyingError": "Invalid flow configuration"
}
}
}
// onLoadingProductsFailed
{
"error": {
"code": "products_loading_failed",
"message": "Failed to load products from the server",
"details": {
"underlyingError": "Network timeout"
}
}
}
// onAppeared
{
"view": {
"id": "3f8a1c7e-9b24-4d51-8e30-6c5b2a9f1d47",
"placementId": "onboarding_paywall",
"variationId": "d21c4b6a-57e8-4f39-b0a2-8c7e13f5d94b",
"locale": "es"
}
}
// onDisappeared
{
//Record the event
}
// onWebPaymentNavigationFinished
{
//Record the event
}您可以只注册需要的事件处理程序,不需要的可以不注册。这样,未使用的事件监听器就不会被创建。所有事件处理程序均为可选。
事件处理器会返回一个布尔值。在模态展示模式下,如果返回 true,则视为展示流程已完成,流程页面会随之关闭,该视图的事件监听器将被移除,原生视图也会被销毁——即使你此前通过 destroy: false 保留了它。在嵌入式 AdaptyFlowView 中,返回值会被忽略:如需关闭流程,停止渲染该组件即可。
某些事件处理器有默认行为,你可以按需覆盖:
onCloseButtonPress:按下关闭按钮时关闭流程。onUrlPress:打开点击的 URL 并保持流程开启。onAndroidSystemBack(仅适用于模态展示):按下 Back 键时保持流程开启。返回true可关闭流程。onRestoreCompleted:恢复购买成功后保持流程开启。返回true可关闭流程。onPurchaseCompleted:购买完成后保持流程开启。返回true可关闭流程。onError:流程渲染失败时关闭流程。
事件处理器
| 事件处理器 | 描述 |
|---|---|
| onCustomAction | 当自定义动作触发时调用,例如用户点击带有该动作的按钮时。onCustomAction 的第二个参数 args 是为未来的 Flow 和付费墙编辑工具功能预留的,无需读取。 |
| onUrlPress | 当用户点击流程中的 URL 时调用。 |
| onAndroidSystemBack | 仅限弹窗展示模式:当用户点击 Android 系统的 Back 按钮时调用。 |
| onCloseButtonPress | 当关闭按钮可见且用户点击时调用。建议在此处理器中关闭流程页面。 |
| onPurchaseCompleted | 当购买完成时调用,无论购买成功、用户取消还是待审批。购买成功时,会返回更新后的 AdaptyProfile。用户取消和待处理付款(如需家长审批)会触发此事件,而不是 onPurchaseFailed。 |
| onPurchaseStarted | 当用户点击”购买”操作按钮开始购买流程时调用。 |
| onPurchaseFailed | 当购买因错误失败时调用(如支付限制、无效产品、网络故障、交易验证失败)。用户取消或待处理付款不会触发此事件,这些情况会触发 onPurchaseCompleted。 |
| onRestoreStarted | 当用户开始购买恢复流程时调用。 |
| onRestoreCompleted | 当购买恢复成功时调用,并返回更新后的 AdaptyProfile。若需在购买恢复后向用户展示更多页面(如欢迎回来页面),请在 Flow 和付费墙编辑工具中设置结果动作。对于流程无法处理的操作(如在用户获得访问权限后打开应用内某个页面),请使用应用代码实现。请参阅订阅状态了解如何验证访问等级。 |
| onRestoreFailed | 当恢复流程失败时调用,并返回 AdaptyError。 |
| onProductSelected | 当流程视图中有任意产品被选中时调用,可用于监控用户在购买前的选择。 |
| onError | 当流程中发生错误时调用,处理器会接收一个 AdaptyError 对象。例如,当流程脚本抛出异常时,错误的 code 为 jsException。当嵌入的 AdaptyFlowView 无法展示其流程时,该处理器也会收到错误——这发生在流程加载失败,或设备运行 iOS 15(流程不支持该系统版本)时。 |
| onLoadingProductsFailed | 当产品加载失败时调用,并返回 AdaptyError。如果在创建视图时未设置 prefetchProducts: true,AdaptyUI 将自行从服务器获取所需对象。 |
| onAppeared | 当流程展示给用户时调用,并返回出现的 view——参见 view 参数。在 iOS 上,当用户点击流程中的网页付费墙按钮并在应用内浏览器中打开网页付费墙时,也会触发此事件。 |
| onDisappeared | 仅限弹窗展示模式:当用户关闭流程时调用。在 iOS 上,当从流程中在应用内浏览器打开的网页付费墙从屏幕消失时,也会触发此事件。 |
| onWebPaymentNavigationFinished | 在尝试打开网页付费墙进行购买后调用,无论成功还是失败。 |
| onAnalytics | 当流程上报分析事件(如页面浏览)时调用。详见下方分析事件。 |
| onRequestAppReview | 为流程中的应用评价请求预留。流程目前尚未触发应用评价请求,无需实现此处理器。 |
| onRequestPermission | 当流程执行请求权限动作时调用。该处理器为异步:请求权限后,若用户授予权限,则以 { status: 'granted' } resolve 该处理器的 Promise;若用户拒绝,则以 { status: 'denied', detail: 'denied' } resolve。若未设置此处理器,用户将看不到系统权限弹窗,流程将执行响应后动作,而非允许时或拒绝时动作。详见在流程中处理权限请求。 |
| onObserverPurchaseInitiated | 仅限观察者模式:当用户在流程中点击购买按钮时调用。Adapty 不会发起购买——请使用您自己的购买代码完成购买,然后将交易上报给 Adapty。详见下方在观察者模式下处理购买。 |
| onObserverRestoreInitiated | 仅限观察者模式:当用户在流程中点击恢复按钮时调用。Adapty 不会执行恢复——请自行完成恢复,然后上报所有已恢复的交易。详见下方在观察者模式下处理购买。 |
view 参数
view 参数需要 React Native SDK 4.0.3 或更高版本。在所有流程事件处理器中,只有 onAppeared 会接收视图自身的描述——一个包含以下字段的 FlowEventView 对象:
| 字段 | 说明 |
|---|---|
| id | 该视图实例的标识符,仅供 SDK 内部使用,与 Adapty 看板中的任何内容无关。 |
| placementId | 获取此流程所对应的版位。 |
| variationId | 流程解析后对应的实验变体,用于将您自己的分析数据归因到 A/B 测试。 |
| locale | 构建该视图时所使用的流程本地化配置。若流程不包含您所请求的语言,该值可能与请求的语言不同。请读取此值,以便将页面其余部分的语言与流程实际渲染的语言保持一致。详见使用本地化及语言代码。 |
分析事件
const unsubscribe = view.setEventHandlers({
onAnalytics(name, params) {
return false; // keep the flow open
},
});流程会向您的应用发送以下分析事件:
| 事件 | 流程在以下情况下发送该事件 |
|---|---|
flow_screen_showed | 用户打开流程中的某个页面时 |
flow_user_input | 输入控件或可选组上报其值时。请参见此表下方的列表 |
flow_permission_requested | 流程向您的应用发送权限请求时 |
flow_permission_answered | 您的应用将权限请求结果传回流程时 |
flow_permission_unanswered | 权限请求发出后 60 秒内,您的应用未传回任何结果时 |
输入事件的触发时机
流程在以下时刻发送 flow_user_input:
- 文本、数字、手机号和电子邮件输入控件:内容发生变化后,输入框失去焦点时。
- 日期、时间和日期和时间输入控件:选择器关闭且存在新值时。
- 单选、多选和切换组:每次点击后立即触发。
- 数字选择器:当包含数字选择器的页面发生以下任一情况时触发,即使用户从未拨动滚轮:
- 跳转到页面、下一步或返回操作离开当前页面。
- 用户点击某个选项或切换开关。
流程还会上报用户输入和选择的值。请参阅处理流程数据了解详情。
屏幕浏览事件
每当用户打开某个流程页面时,该流程都会上报 flow_screen_showed 事件。Adapty 在自有流程分析中统计这些事件,同时也会将其推送给您的应用,以便您在自己的分析工具中构建相同的漏斗。
| 参数 | 说明 |
|---|---|
instanceId | 用户打开的页面 ID。 |
screen_order | 该页面在流程中的位置。 |
is_last_screen | 当该页面没有后续页面时为 true。有分支的流程可以在多个不同页面结束,每个结束页面均上报 true。若付费墙页面的任意结果动作(无论购买或恢复结果如何)会跳转到其他页面,则该付费墙页面上报 false。Navigate back 动作不计入此逻辑。如果所有用户在到达付费墙之前都会经过某个页面,则跳转到该页面的动作也不计入。 |
此事件的 isBackendEvent 和 isCustomerEvent 均为 true:Adapty 会持续统计该事件,您的应用也会同时接收到它。
要将屏幕浏览事件转发到您的产品分析工具,请参阅追踪流程屏幕浏览。
权限请求事件
对于请求系统权限的流程,权限事件会显示有多少用户授予了每项权限。
对于每个权限请求,流程会向应用的分析回调发送以下事件:
flow_permission_requested:流程已向应用发送权限请求。在等待请求结果期间,流程不会发送其他请求,也不会为该请求发送任何其他事件。其参数如下:instanceId:发送请求的屏幕 ID。permission:权限值。with_outcome:若 When allowed、When denied 或 After response 触发了非 Do nothing 的操作,则为true。
flow_permission_answered:应用已将结果传回流程。其参数如下:instanceId:发送请求的屏幕 ID。permission:权限值。result:若应用传回了已授权的结果,则为true。detail_result:应用随结果传入的参数(如有)。outcome:根据result和detail_result得出的一个综合值,对应结果及其参数。详见下方表格。
flow_permission_unanswered:应用在权限请求发出后 60 秒内未传回结果。每次请求流程只发送一次该事件;若流程在此之前已关闭,则不发送该事件。若应用随后传回了结果,流程仍会发送flow_permission_answered。其参数如下:instanceId:发送请求的屏幕 ID。当outcome参数为left_screen时,该 ID 仍属于原屏幕,而非用户当前所在的屏幕。permission:权限值。with_outcome:若 When allowed、When denied 或 After response 触发了非 Do nothing 的操作,则为true。outcome:若用户仍停留在发送请求的屏幕上,则为on_screen;若用户已离开该屏幕,则为left_screen。若用户在 60 秒内离开后又返回该屏幕,结果为on_screen。
flow_permission_answered 的 outcome 属性反映的是应用传回的结果,而非流程执行的操作:
| 应用传回的结果及参数 | outcome |
|---|---|
已授权,参数为 limited 或 provisional | 与参数相同:limited 或 provisional |
| 已授权,参数为其他值或无参数 | granted |
未授权,参数为 denied、restricted、permanently_denied 或 unsupported | 与参数相同:denied、restricted、permanently_denied 或 unsupported |
| 未授权,参数为其他值 | other |
| 未授权,且无参数。部分 Adapty SDK 在应用没有处理器时会传回此结果 | no_status |
测试权限请求时,请对比事件与系统对话框中的选择是否一致。若存在差异,请参考以下列表查找原因:
outcome为no_status,但您拒绝了权限:应用传回了未授权结果,但未附带denied参数。请在结果中附带denied参数。outcome为other:应用传回结果时附带了流程无法识别的参数,例如拼写错误或错误信息。detail_result参数会显示该参数内容。- 流程发送了
flow_permission_unanswered:应用在 60 秒内未传回任何结果。请为流程设置处理器,并对每个权限请求都传回结果,即使发生异常或超时也不例外。
在观察者模式下处理购买
如果你以观察者模式(observerMode: true)激活了 SDK 并展示了 Adapty 渲染的流程,SDK 不会自动为你发起购买。当用户点击购买或恢复按钮时,SDK 会调用 onObserverPurchaseInitiated 或 onObserverRestoreInitiated。请用你自己的代码执行购买或恢复操作,通过提供的回调驱动流程的加载指示器,并在完成后向 Adapty 上报交易。
const unsubscribe = view.setEventHandlers({
onObserverPurchaseInitiated(product, onStartPurchase, onFinishPurchase) {
onStartPurchase(); // show the flow's loading indicator
myPurchaseApi(product.vendorProductId)
.then((transactionId) => adapty.reportTransaction(transactionId))
.finally(() => onFinishPurchase()); // hide the loading indicator
return false; // keep the flow open; dismiss it yourself after success, or let the flow continue
},
onObserverRestoreInitiated(onStartRestore, onFinishRestore) {
onStartRestore();
myRestoreApi()
.finally(() => onFinishRestore());
return false;
},
});本指南介绍购买、恢复、产品选择和付费墙渲染的事件处理方式。你还需要实现按钮处理功能(关闭付费墙、打开链接等)。详情请参阅按钮操作处理指南。
使用付费墙编辑工具配置的付费墙无需额外代码即可完成购买和恢复购买操作。但它们会触发一些事件,你的应用可以对这些事件做出响应。这些事件包括按钮点击(关闭按钮、URL、产品选择等),以及付费墙上购买相关操作的通知。请参阅以下内容,了解如何响应这些事件。
本指南仅涵盖在旧版编辑工具中构建的付费墙,需要 Adapty SDK v3.0 或更高版本。
要控制或监控移动应用中付费墙屏幕上发生的流程,请实现以下事件处理器:
对于 React 组件,你可以通过 AdaptyPaywallView 组件中各自对应的事件处理器属性来处理事件:
function MyPaywall({ paywall }) {
const onCloseButtonPress = useCallback<EventHandlers['onCloseButtonPress']>(() => {}, []);
const onProductSelected = useCallback<EventHandlers['onProductSelected']>((productId) => {}, []);
const onPurchaseStarted = useCallback<EventHandlers['onPurchaseStarted']>((product) => {}, []);
const onPurchaseCompleted = useCallback<EventHandlers['onPurchaseCompleted']>((purchaseResult, product) => {}, []);
const onPurchaseFailed = useCallback<EventHandlers['onPurchaseFailed']>((error, product) => {}, []);
const onRestoreStarted = useCallback<EventHandlers['onRestoreStarted']>(() => {}, []);
const onRestoreCompleted = useCallback<EventHandlers['onRestoreCompleted']>((profile) => {}, []);
const onRestoreFailed = useCallback<EventHandlers['onRestoreFailed']>((error) => {}, []);
const onPaywallShown = useCallback<EventHandlers['onPaywallShown']>(() => {}, []);
const onRenderingFailed = useCallback<EventHandlers['onRenderingFailed']>((error) => {}, []);
const onLoadingProductsFailed = useCallback<EventHandlers['onLoadingProductsFailed']>((error) => {}, []);
const onUrlPress = useCallback<EventHandlers['onUrlPress']>((url) => {
Linking.openURL(url);
}, []);
const onCustomAction = useCallback<EventHandlers['onCustomAction']>((actionId) => {}, []);
const onWebPaymentNavigationFinished = useCallback<EventHandlers['onWebPaymentNavigationFinished']>(() => {}, []);
return (
<AdaptyPaywallView
paywall={paywall}
style={styles.container}
onCloseButtonPress={onCloseButtonPress}
onProductSelected={onProductSelected}
onPurchaseStarted={onPurchaseStarted}
onPurchaseCompleted={onPurchaseCompleted}
onPurchaseFailed={onPurchaseFailed}
onRestoreStarted={onRestoreStarted}
onRestoreCompleted={onRestoreCompleted}
onRestoreFailed={onRestoreFailed}
onPaywallShown={onPaywallShown}
onRenderingFailed={onRenderingFailed}
onLoadingProductsFailed={onLoadingProductsFailed}
onUrlPress={onUrlPress}
onCustomAction={onCustomAction}
onWebPaymentNavigationFinished={onWebPaymentNavigationFinished}
/>
);
}事件示例(点击展开)
// onCloseButtonPress
{
//Record the event
}
// onAndroidSystemBack
{
//Record the event
}
// onUrlPress
{
"url": "https://example.com/terms"
}
// onCustomAction
{
"actionId": "login"
}
// onProductSelected
{
"productId": "premium_monthly"
}
// onPurchaseStarted
{
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onPurchaseCompleted - Success
{
"purchaseResult": {
"type": "success",
"profile": {
"accessLevels": {
"premium": {
"id": "premium",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
}
}
},
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onPurchaseCompleted - Cancelled
{
"purchaseResult": {
"type": "user_cancelled"
},
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onPurchaseFailed
{
"error": {
"code": "purchase_failed",
"message": "Purchase failed due to insufficient funds",
"details": {
"underlyingError": "Insufficient funds in account"
}
},
"product": {
"vendorProductId": "premium_monthly",
"localizedTitle": "Premium Monthly",
"localizedDescription": "Premium subscription for 1 month",
"price": {
"amount": 9.99,
"currencyCode": "USD",
"currencySymbol": "$",
"localizedString": "$9.99"
}
}
}
// onRestoreCompleted
{
"profile": {
"accessLevels": {
"premium": {
"id": "premium",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
},
"subscriptions": [
{
"vendorProductId": "premium_monthly",
"isActive": true,
"expiresAt": "2024-02-15T10:30:00Z"
}
]
}
}
// onRestoreFailed
{
"error": {
"code": "restore_failed",
"message": "Purchase restoration failed",
"details": {
"underlyingError": "No previous purchases found"
}
}
}
// onRenderingFailed
{
"error": {
"code": "rendering_failed",
"message": "Failed to render paywall interface",
"details": {
"underlyingError": "Invalid paywall configuration"
}
}
}
// onLoadingProductsFailed
{
"error": {
"code": "products_loading_failed",
"message": "Failed to load products from the server",
"details": {
"underlyingError": "Network timeout"
}
}
}
// onPaywallShown
{
//Record the event
}
// onPaywallClosed
{
//Record the event
}
// onWebPaymentNavigationFinished
{
//Record the event
}您可以只注册所需的事件处理器,忽略不需要的。这样就不会创建未使用的事件监听器。所有事件处理器均为可选。
事件处理器返回一个布尔值。若返回 true,则视为展示流程已完成,付费墙界面随即关闭,该视图的事件监听器也会被移除。
某些事件处理程序具有默认行为,您可以根据需要覆盖它们:
onCloseButtonPress:点击关闭按钮时关闭付费墙。onUrlPress:打开点击的 URL 并保持付费墙不关闭。onAndroidSystemBack(仅适用于模态展示):按下 Back 按钮时关闭付费墙。onRestoreCompleted:恢复成功后关闭付费墙。onPurchaseCompleted:除非用户取消,否则关闭付费墙。onRenderingFailed:付费墙渲染失败时关闭付费墙。
事件处理程序
| 事件处理器 | 描述 |
|---|---|
| onCustomAction | 当用户执行自定义操作时触发,例如点击自定义按钮。 |
| onUrlPress | 当用户点击付费墙中的 URL 时触发。 |
| onAndroidSystemBack | 仅限模态展示:当用户点击 Android 系统的 Back 按钮时触发。 |
| onCloseButtonPress | 当关闭按钮可见且用户点击它时触发。建议在此处理器中关闭付费墙页面。 |
| onPurchaseCompleted | 当购买完成时触发,无论是成功、被用户取消还是待审批。购买成功时会提供更新后的 AdaptyProfile。用户取消和待处理的付款(例如需要家长批准)会触发此事件,而非 onPurchaseFailed。 |
| onPurchaseStarted | 当用户点击”购买”操作按钮以启动购买流程时触发。 |
| onPurchaseFailed | 当购买因错误失败时触发(例如付款限制、无效产品、网络故障、交易验证失败)。用户取消或待处理付款不会触发此事件,那些情况会触发 onPurchaseCompleted。 |
| onRestoreStarted | 当用户开始购买恢复流程时触发。 |
| onRestoreCompleted | 当购买恢复成功时触发,并提供更新后的 AdaptyProfile。如果用户已获得所需的 accessLevel,建议关闭页面。请参阅订阅状态主题了解如何检查。 |
| onRestoreFailed | 当恢复流程失败时触发,并提供 AdaptyError。 |
| onProductSelected | 当付费墙视图中的任意产品被选中时触发,可让你监控用户在购买前选择的内容。 |
| onRenderingFailed | 当视图渲染过程中发生错误时触发,并提供 AdaptyError。此类错误通常不应发生,如果遇到,请告知我们。 |
| onLoadingProductsFailed | 当产品加载失败时触发,并提供 AdaptyError。如果你在创建视图时未设置 prefetchProducts: true,AdaptyUI 将自行从服务器获取所需对象。 |
| onPaywallShown | 当付费墙展示给用户时触发。在 iOS 上,当用户点击付费墙内的网页付费墙按钮并在应用内浏览器中打开网页付费墙时,也会触发此事件。 |
| onPaywallClosed | 仅限模态展示:当用户关闭付费墙时触发。在 iOS 上,当从付费墙在应用内浏览器中打开的网页付费墙从屏幕上消失时,也会触发此事件。 |
| onWebPaymentNavigationFinished | 在尝试打开网页付费墙进行购买后触发,无论成功或失败。 |