For the complete documentation index, see llms.txt. This page is also available as Markdown.

Notification.requestAgreement

函数式 API requestNotificationAgreement也可以通过它使用相同的功能。

功能说明

请求通知同意界面,并将同意结果 onEvent 通过回调传递。Toss App Android/iOS 5.255.0 可在以上使用。

options.templateCode请在其中填入在 Apps in Toss 控制台 > 小应用 > 智能发送中编写的模板代码。

以事件风格运行,并通过返回值获得一个用于解除应用桥接回调的函数。收到结果后请务必解除。

调用前 Notification.requestAgreement.isSupported()可通过它确认是否支持。若在不支持的版本中调用, UNSUPPORTED_APP_VERSION 会发生错误。函数式 API requestNotificationAgreement会不受版本影响地尝试订阅。

类型

Notification.requestAgreement(params: RequestNotificationAgreementOptions): () => void;

Params

interface RequestNotificationAgreementOptions {
  options: { templateCode: string };
  onEvent: (result: { type: NotificationAgreementResult }) => void;
  onError: (error: unknown) => void | Promise<void>;
}

type NotificationAgreementResult =
  "newAgreement" | "alreadyAgreed" | "agreementRejected";

Response

返回一个用于解除应用桥接回调的 cleanup 函数。

错误

错误代码 onError可通过……接收,或由包裹调用的 try/catch中捕获到的错误的 error.code 值。

代码
说明

UNSUPPORTED_APP_VERSION

如果当前运行的 Toss App 版本不支持此功能,调用后会立即发生。 Notification.requestAgreement.isSupported()可通过它提前确认,发生时 error.message请向用户显示(更新提示文案)。

示例代码

这有帮助吗?