元服务领用服务通知模板后,主动向登录华为账号的用户发起订阅请求,Push Kit将向用户弹出授权弹窗。当用户在弹窗中选择后,Push Kit将返回用户的订阅选择给元服务,元服务根据用户的订阅结果处理消息下发逻辑。
一次性订阅消息弹窗样式请参考如下示例:

一次性订阅消息弹窗中包含以下信息:
其中用户授权订阅按钮分为“允许”和“不允许”:
当用户勾选“总是保持以上选择”之后,下次订阅调用serviceNotification.requestSubscribeNotification()不会弹窗,保持之前的选择,修改选择需要打开元服务通知管理设置页进行修改。
长期订阅消息弹窗样式请参考如下示例:

长期订阅消息弹窗中包含以下信息:
其中用户授权订阅按钮分为“允许”和“不允许”:
import { UIAbility } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; import { serviceNotification } from '@kit.PushKit'; export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the page. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); }); } async requestSubscribeNotification() { try { // entityIds请替换为待订阅的模板ID let entityIds: string[] = ['13B6000E24008000', '13B90C82D3802680']; let type: serviceNotification.SubscribeNotificationType = serviceNotification.SubscribeNotificationType.SUBSCRIBE_WITH_HUAWEI_ID; const res: serviceNotification.RequestResult = await serviceNotification.requestSubscribeNotification(this.context, entityIds, type); hilog.info(0x0000, 'testTag', 'Succeeded in requesting serviceNotification: %{public}s', JSON.stringify(res.entityResult)); } catch (err) { let e: BusinessError = err as BusinessError; hilog.error(0x0000, 'testTag', 'Failed to request serviceNotification: %{public}d %{public}s', e.code, e.message); } } async onForeground(): Promise<void> { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); try { // 请确保加载页面完成,可以获取UIAbilityContext后调用方法 await this.requestSubscribeNotification(); } catch (err) { let e: BusinessError = err as BusinessError; hilog.error(0x0000, 'testTag', 'Request subscribe notification failed: %{public}d %{public}s', e.code, e.message); } } }
'ACCEPTED'表示用户同意订阅该条模板ID对应的通知模板。
'REJECTED'表示用户拒绝订阅该条模板ID对应的通知模板。
'FILTERED'表示该模板因为模板标题同名被后台过滤。
'BANNED'表示模板已被后台封禁。
详情见RequestResult。