说明
本文档中提供移动推送相关的基础能力,包含注册、账号、标签、属性,此文档适用于 SDK 1.0.0 beta 或更高版本。
TPNS主要接口类如下:
类名 | 说明 |
TPush | 创建移动推送服务推送对象 |
移动推送服务相关配置 | |
移动推送服务推送接口类 |
引用SDK
import { TPNS, TPush } from '@ohos/tpns';
初始化
TPush.createTPushClient
接口说明
App 只有在完成移动推送的初始化才可以使用移动推送 SDK 提供的 Push 服务,在这里,请确保配置信息中设置的 AccessId 和 AccessKey、接入点(广州集群可选)正确。初始化成功会返回 TPush 服务推送接口对象,当参数传入错误时会抛出异常,需要做好异常处理。
TPush.createTPushClient(applicationContext:Context,configOptions:TPNS.ConfigOptions): TPNS.TPushClient|never
示例代码
try { let tpnsClient = TPush.createTPushClient(context, { accessId: 150000xxxx, //您应用对应移动推送控制台生成的accessId accessKey: "您的accessKey",//您应用对应移动推送控制台生成的accessKey host: "tpns.tencent.com", //接入点:默认广州集群 debugMode: true //上线后记得设置为false }); this.tpnsClient.setMessageReceiver(new MessageReiver()); } catch (err) { //TODO:: TPush.createTPushClient 传递的必选参数为空或者非法会抛出异常此处要注意处理 }
参数说明
参数名 | 类型 | 必填 | 说明 |
applicationContext | Context | 是 | 应用的applicationContext |
configOptions | 是 | 推送sdk相关的配置参数 |
返回值
类型 | 说明 |
返回移动推送SDK 推送服务操作接口 |
设置接收消息回调
初始化完移动推送服务后,需要立即设置接收消息回调方法,避免遗漏下发的推送消息。
接口说明
setMessageReceiver(messageReciver:MessageReceiver);
示例代码
class MessageReiver implements TPNS.MessageReceiver { public onNotificationDeleted(err:Error,notificationMessage: TPNS.NotificationMessage): void { if(err){ console.error(TAG, "onNotificationDeleted fail, err:" + JSON.stringify(err as BusinessError<string>) + " , notificationMessage:"+JSON.stringify(notificationMessage)); }else { console.debug(TAG, "onNotificationDeleted notificationMessage:" + JSON.stringify(notificationMessage)); } } public onNotificationShow(err:Error,notificationMessage: TPNS.NotificationMessage): void { if(err){ console.error("TPush-Demo", "onNotificationShowed fail, err:" + JSON.stringify(err as BusinessError<string>) + " , notificationMessage:"+JSON.stringify(notificationMessage)); }else { console.debug("TPush-Demo", "onNotificationShowed notificationMessage:" + JSON.stringify(notificationMessage)); } } public onTextMessage(err:Error,pushMessage: TPNS.PushMessage): void { if(err) { console.error("TPush-Demo", "onTextMessage fail:" + JSON.stringify(err as BusinessError<string>)); }else{ console.debug("TPush-Demo", "onTextMessage pushMessage:" + JSON.stringify(pushMessage)); } } }//初始化移动推送服务后,设置接收推送消息回调this.tpnsClient.setMessageReceiver(new MessageReiver());
参数说明
参数名 | 类型 | 必填 | 说明 |
messageReceiver | 是 | 开发者自行实现的消息回调接口类的对象 |
注册与反注册
App 只有在完成移动推送的初始化与注册后才可以移动推送 SDK 提供 Push 服务。
注册成功后,会返回设备 Token,Token 用于标识设备唯一性,同时也是移动推送维持与后台连接的唯一身份标识。
注册接口通常提供使用 Promise 异步回调和使用 callback 异步回调的接口,请根据业务需要决定选择接口。
设备注册
普通注册只注册当前设备,后台能够针对不同的设备 Token 发送推送消息,以下有4个版本的 API 接口方法:
接口说明
registerPush():Promise<string> //使用Promise异步回调
示例代码
this.tpnsClient.registerPush().then((data) => { console.error("TPush-Demo", "registerPush result:" + data); }).catch((err: BusinessError<string>) => { console.error("TPush-Demo", "registerPush fail err:" + JSON.stringify(err)); })
返回值
类型 | 说明 |
Promise<string> | 注册返回的移动推送 token,发生错误时会抛出异常 |
接口说明
registerPush(callback: Callback<string>)//使用callback异步回调
示例代码
this.tpnsClient.registerPush((err,result)=>{ if(err){ console.error("TPush-Demo", "registerPush fail err:" + JSON.stringify(err)); }else{ console.error("TPush-Demo", "registerPush result:" + result); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
callback | Callback<string> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
接口说明
registerPushWithAccount(account:TPNS.Account):Promise<string> //使用Promise异步回调
示例代码
let account: TPNS.Account = { account:"testaccount", accountType:0 }; this.tpnsClient.registerPushWithAccount(account).then((data) => { console.error("TPush-Demo", "registerPushWithAccount result:" + data); }).catch((err: BusinessError<string>) => { console.error("TPush-Demo", "registerPushWithAccount fail err:" + JSON.stringify(err)); })
参数说明
参数名 | 类型 | 必填 | 说明 |
account | 是 | 不能为空与 undefined,注册时携带的账号信息,绑定成功后可以通过该账号下发推送 |
返回值
类型 | 说明 |
Promise<string> | 注册返回的移动推送 token,发生错误时会抛出异常 |
接口说明
registerPushWithAccount(account:TPNS.Account, callback: Callback<string>) //使用callback异步回调
示例代码
let account: TPNS.Account = { account:"testaccount", accountType:0 }; this.tpnsClient.registerPushWithAccount(account,(err,result)=>{ if(err){ console.error("TPush-Demo", "registerPushWithAccount fail err:" + JSON.stringify(err)); }else{ console.error("TPush-Demo", "registerPushWithAccount result:" + result); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
account | 是 | 不能为空与undefined,注册时携带的账号信息,绑定成功后可以通过该账号下发推送 | |
callback | Callback<string> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
反注册
注意:
调用反注册接口后,需要重新调用注册接口才可接收到推送。
当用户已退出或 App 被关闭,不再需要接收推送时,可以取消注册 App,即反注册(一旦设备反注册,直到这个设备重新注册成功期间内,下发的消息该设备都无法收到)。
接口说明
unRegisterPush():Promise<void>
示例代码
this.tpnsClient.unRegisterPush().then(() => { console.error("TPush-Demo", "Promise unregister success:"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "unregister fail err:" + JSON.stringify(err)); })
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
unRegisterPush(callback: Callback<void>)//使用callback异步回调
示例代码
this.tpnsClient.unRegisterPush((err)=>{ if(err){ console.error("TPush-Demo", "unregister faile:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "unregister success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
推送通知(展现在通知栏)
指的是在设备通知栏展示的内容,由移动推送 SDK 完成所有的操作,App 可以监听通知被打开的行为,即在前台下发的通知,无需 App 做任何处理,默认会展示在通知栏。
说明:
成功注册移动推送服务后,通常不需要任何设置便可下发通知。
通常来说,常规的通知,能够满足大部分业务需求,如果需要更灵活的方式,请考虑使用透传消息。
获取通知
接口说明
移动推送 SDK 提供回调接口供开发者获取抵达的通知内容,可以通过setMessageReceiver接口设置接收推送消息回调,设置推送消息中对象的onNotificationShowed(err:Error,notificationMessage: TPNS.NotificationMessage): void 方法实现,notificationMessage 对象提供读取通知内容的接口。
注意:
因鸿蒙厂商通道未提供通知抵达回调方法,且当 App 进程未运行时,厂商通道的抵达回调方法无法触发。因此 SDK 内提供的回调接口 onNotificationShowed 仅支持移动推送自建通道下发通知抵达的监听,不支持鸿蒙通道消息抵达的监听。
public onNotificationShow(err:Error,notificationMessage: TPNS.NotificationMessage): void
示例代码
public onNotificationShow(err:Error,notificationMessage: TPNS.NotificationMessage): void { if(err){ console.error("TPush-Demo", "onNotificationShow fail, err:" + JSON.stringify(err as BusinessError<string>) + " , notificationMessage:"+JSON.stringify(notificationMessage)); }else { console.debug("TPush-Demo", "onNotificationShow notificationMessage:" + JSON.stringify(notificationMessage)); } }
参数说明
参数名 | 类型 | 必填 | 说明 |
err | BusinessError | 是 | 当回调方法被调用时,err 不为 null 或者undefined,则代表通知展示失败 |
notificationMessage | 是 | 当回调方法被调用时,err 为 null 或者 undefined,则代表通知展示成功,此时可以获取通知相关信息 |
获取通知点击结果
通知点击
使用移动推送 SDK 默认已经统计通知/消息的抵达量、通知的点击。点击通知会打开对应的 UIAbility,在 UIAbility 的 onCreate(want:Want, launchParam: AbilityConstant.LaunchParam) 或 onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void 中调用移动推送通过移动推送 SDK 提供parseNotificationMessage(want: Want):TPNS.NotificationMessage;方法来判断是否是移动推送的通知点击。
接口说明
parseNotificationMessage(want: Want):TPNS.NotificationMessage;
示例代码
onCreate(want:Want, launchParam: AbilityConstant.LaunchParam) { super.onCreate(want,launchParam); const notificationMessage:TPNS.NotificationMessage = this.tpnsClient.parseNotificationMessage(want); if(notificationMessage){ //移动推送通知点击 console.debug("TPush-Demo", "onNotificationClick notificationMessage:" + JSON.stringify(notificationMessage)); }else{ //非移动推送通知点击,进行其他逻辑处理 } } onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { const notificationMessage:TPNS.NotificationMessage = this.tpnsClient.parseNotificationMessage(want); if(notificationMessage){ //移动推送通知点击 console.debug("TPush-Demo", "onNotificationClick notificationMessage:" + JSON.stringify(notificationMessage)); }else{ //非移动推送通知点击,进行其他逻辑处理 } }
参数说明
参数名 | 类型 | 必填 | 说明 |
want | Want | 是 | 不能为空与 undefined,UIAbility 的 onCreate 或onNewWant 方法中的 want 参数,用于移动推送SDK 判断是否是移动推送点击移动推送通知触发的。 |
返回值
类型 | 说明 |
判断 Ability 打开时是不是点击通知触发,是则返回不为空的通知消息对象 |
通知移除监听
接口说明
移动推送 SDK 提供回调接口供开发者获取移除的通知动作,可以通过setMessageReceiver接口设置推送消息接收器,设置推送消息接收器中对象的onNotificationDeleted(err:Error,notificationMessage: TPNS.NotificationMessage): void 方法实现.
注意:
因鸿蒙厂商通道未提供通知抵达移除回调方法,厂商通道的通知移除方法无法触发,并且应用进程被杀掉后通过移动推送通道或者本地通知触发展示的通知也收不到此回调。因此 SDK 内提供的移除回调接口 onNotificationDeleted 仅支持移动推送自建通道下发通知以及本地通知触发的通知。
public onNotificationDeleted(err:Error,notificationMessage: TPNS.NotificationMessage): void
示例代码
public onNotificationDeleted(err:Error,notificationMessage: TPNS.NotificationMessage): void { if(err){ console.error(TAG, "onNotificationDeleted fail, err:" + JSON.stringify(err as BusinessError<string>) + " , notificationMessage:"+JSON.stringify(notificationMessage)); }else { console.debug(TAG, "onNotificationDeleted notificationMessage:" + JSON.stringify(notificationMessage)); } }
参数说明
参数名 | 类型 | 必填 | 说明 |
err | BusinessError | 是 | 当回调方法被调用时,err 不为 null 或者undefined,则代表通知展示失败 |
notificationMessage | 是 | 当回调方法被调用时,err 为 null 或者 undefined,则代表通知展示成功,此时可以获取通知相关信息 |
清除所有通知
接口说明
清除本 App 在通知栏上的所有通知。
cancelAllNotification():Promise<void>//使用Promise异步回调
示例代码
this.tpnsClient.cancelAllNotification().then(()=>{ console.debug("TPush-Demo", "cancelNotification success"); }).catch((err:BusinessError)=>{ console.debug("TPush-Demo", "cancelNotification fail err:" + JSON.stringify(err)); })
返回值
类型 | 说明 |
Promise<void> | 失败时抛出异常 |
接口说明
anelAllNotification(callback:Callback<void>);
示例代码
this.tpnsClient.cancelAllNotification((err)=>{ if(err){ console.debug("TPush-Demo", "cancelNotification fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "cancelNotification success"); } })
参数说明
参数名 | 类型 | 必填 | 说明 |
callback | Callback<void> | 是 | 回调函数。不能为空, err 不为空则表示失败 |
推送透传消息(消息不展示到通知栏)
指的是由移动推送下发给 App 的内容,需要 App 通过setMessageReceiver接口设置推送消息接收方法,实现并自主处理所有操作过程,也就是说,下发的消息默认是不会展示在通知栏的,移动推送只负责将消息从移动推送服务器下发到 App 这个过程,不负责消息的处理逻辑,需要 App 自己实现。
消息指的是由开发者通过前台或后台脚本下发的文本消息,移动推送只负责将消息传递给 App,App 完全自主负责消息体的处理。
消息具有灵活性强和高度定制性的特点,更适合 App 自主处理个性化业务需求,例如下发 App 配置信息、自定义处理消息的存储和展示等。
获取透传消息
接口说明
public onTextMessage(err:Error,pushMessage: TPNS.PushMessage): void
示例代码
public onTextMessage(err:Error,pushMessage: TPNS.PushMessage): void { if(err) { console.error("TPush-Demo", "onTextMessage fail:" + JSON.stringify(err as BusinessError<string>)); }else{ console.debug("TPush-Demo", "onTextMessage pushMessage:" + JSON.stringify(pushMessage)); } }
参数说明
参数名 | 类型 | 必填 | 说明 |
err | BusinessError | 是 | 当回调方法被调用时,err 不为 null 或者undefined,则代表通知展示失败 |
pushMessage | 是 | 当回调方法被调用时,err 不为 null 或者undefined,则代表透传消息抵达成功,此时可以获取推送相关信息 |
本地通知
增加本地通知
本地通知由用户自定义设置,保存在本地。当应用打开,移动推送 SDK 服务 会根据网络心跳,判断当前是否有通知(5分钟一次), 本地通知需要 移动推送服务 开启才能弹出,可能存在5分钟左右延时。(当设置的时间小于当前设备时间通知弹出)
接口说明
addLocalNotification(localMessage:TPNS.LocalMessage):Promise<void>; //使用Promise异步回调
示例代码
addLocalMessage(inboxNotification:boolean){let inlines:string[] = ["第一行","第二行","第三行","第四行"]; let localMessage:TPNS.LocalMessage; if(inboxNotification){ localMessage = { type:TPNS.LocalMessageType.NOTIFICATION, title:"我是本地多行文本通知标题", content:"我是本地通知内容", action_type:TPNS.LocalMessageActionType.OPEN_APP, inlines:inlines } as TPNS.LocalMessage; }else{ localMessage = { type:TPNS.LocalMessageType.NOTIFICATION, title:"我是本地通知标题", content:"我是本地通知内容", action_type:TPNS.LocalMessageActionType.OPEN_APP, action:"action.tpns.push" } as TPNS.LocalMessage; }this.tpnsClient.addLocalNotification(localMessage).then(()=>{ console.debug("TPush-Demo", "addLocalMessage success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "addLocalMessage fail err:" + JSON.stringify(err)); })}
参数说明
参数名 | 类型 | 必填 | 说明 |
localMessage | 是 | 要展示的本地通知对象,不能为空或 undefined |
返回值
类型 | 说明 |
Promise<void> | 失败时抛出异常,参考 err 信息 |
接口说明
addLocalNotification(localMessage:TPNS.LocalMessage, callback:Callback<void>); //使用callback异步回调
示例代码
addLocalMessage(inboxNotification:boolean){let inlines:string[] = ["第一行","第二行","第三行","第四行"]; let localMessage:TPNS.LocalMessage; if(inboxNotification){ localMessage = { type:TPNS.LocalMessageType.NOTIFICATION, title:"我是本地多行文本通知标题", content:"我是本地通知内容", action_type:TPNS.LocalMessageActionType.OPEN_APP, inlines:inlines } as TPNS.LocalMessage; }else{ localMessage = { type:TPNS.LocalMessageType.NOTIFICATION, title:"我是本地通知标题", content:"我是本地通知内容", action_type:TPNS.LocalMessageActionType.OPEN_APP, action:"action.tpns.push" } as TPNS.LocalMessage; }this.tpnsClient.addLocalNotification(localMessage, (err) => { if(err){ console.error("TPush-Demo", "addLocalMessage fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "addLocalMessage success"); } });}
参数说明
参数名 | 类型 | 必填 | 说明 |
localMessage | 是 | 要展示的本地通知对象,不能为空与 undefined | |
callback | Callback<void> | 是 | 回调函数。不能为空, err 不为空则表示失败 |
清除本地通知
接口说明
清除本 App 已经创建但未弹出的本地通知。
clearLocalNotification():void;
示例代码
this.tpnsClient.clearLocalNotification();
账号管理
添加账号
接口说明
添加或更新账号。若原来没有该类型账号,则添加;若原来有,则覆盖。可以同时添加多个账号,一个账号对应一个账号类型。
说明:
每个账号最多支持绑定100个 token。
账号可以是邮箱、QQ 号、手机号、用户名等任意类别的业务账号,账号类型取值可参考 账号类型取值表。
同一个账号绑定多个设备时,后台将默认推送消息到最后绑定的设备,如需推送所有绑定的设备可查看 Rest API 文档中 account_push_type 参数设置。
接口说明
upsetAccount(accounts:ArrayList<TPNS.Account>):Promise<void>; //使用Promise异步回调
示例代码
let accounts: ArrayList<TPNS.Account> = new ArrayList<TPNS.Account>(); const account: TPNS.Account = { account:"testaccount", accountType:0 }; accounts.add(account); const account1: TPNS.Account = { account:"testaccount2", accountType:1 }; accounts.add(account1); console.debug("TPush-Demo", "accounts:" + JSON.stringify(accounts.convertToArray())); this.tpnsClient.upsetAccount(accounts).then(()=>{ console.debug("TPush-Demo", "upsetAccount success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "upsetAccount fail err:" + JSON.stringify(err)); })
参数说明
参数名 | 类型 | 必填 | 说明 |
accounts | 是 | 要添加的账号列表,不能为空与undefined |
说明:
每个账号最多支持绑定100个 token。
账号可以是邮箱、QQ 号、手机号、用户名等任意类别的业务账号,账号类型取值可参考 账号类型取值表。
同一个账号绑定多个设备时,后台将默认推送消息到最后绑定的设备,如需推送所有绑定的设备可查看 Rest API 文档中 account_push_type 参数设置。
返回值
类型 | 说明 |
Promise<void> | 失败时会抛出异常 |
接口说明
upsetAccount(accounts:ArrayList<TPNS.Account>, callback:Callback<void>); //使用callback异步回调
示例代码
let accounts: ArrayList<TPNS.Account> = new ArrayList<TPNS.Account>(); const account: TPNS.Account = { account:"testaccount", accountType:0 }; accounts.add(account); const account1: TPNS.Account = { account:"testaccount2", accountType:1 }; accounts.add(account1); console.debug("TPush-Demo", "accounts:" + JSON.stringify(accounts.convertToArray())); this.tpnsClient.upsetAccount(accounts, (err) => { if(err){ console.error("TPush-Demo", "upsetAccount fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "upsetAccount success"); } })
参数说明
参数名 | 类型 | 必填 | 说明 |
accounts | 是 | 要添加的账号列表,不能为空与undefined | |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
说明:
每个账号最多支持绑定100个 token。
账号可以是邮箱、QQ 号、手机号、用户名等任意类别的业务账号,账号类型取值可参考 账号类型取值表。
同一个账号绑定多个设备时,后台将默认推送消息到最后绑定的设备,如需推送所有绑定的设备可查看 Rest API 文档中 account_push_type 参数设置。
添加手机号
接口说明
添加或更新手机号码。若原来没有绑定手机号码,则绑定;
说明:
手机号格式为
+[国家或地区码][手机号]
,例如+8613711112222(其中前面有一个+号 ,86为国家或地区码,13711112222为手机号)。若绑定的手机号不带国家或地区码,则移动推送下发短信时自动增加+86的前缀;若带上国家或地区码,则按照指定的号码绑定。如需删除绑定的手机号,则需调用 delAccounts
接口并设置 accountType 为 1002
。upsertPhoneNumber(phoneNumber:string):Promise<void>; //使用Promise异步回调
示例代码
const phoneNumber = "18682358888"; this.tpnsClient.upsertPhoneNumber(phoneNumber).then(()=>{ console.debug("TPush-Demo", "upsertPhoneNumber success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "upsertPhoneNumber fail err:" + JSON.stringify(err)); })
参数说明
参数名 | 类型 | 必填 | 说明 |
phoneNumber | string | 是 | E.164标准,格式为+[国家或地区码][手机号],例如+8613711112222。SDK 内部加密传输。 |
说明:
手机号格式为
+[国家或地区码][手机号]
,例如+8613711112222(其中前面有一个+号 ,86为国家或地区码,13711112222为手机号)。若绑定的手机号不带国家或地区码,则移动推送下发短信时自动增加+86的前缀;若带上国家或地区码,则按照指定的号码绑定。如需删除绑定的手机号,则需调用 delAccounts
接口并设置 accountType 为 1002
。返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
upsertPhoneNumber(phoneNumber:string, callback:Callback<boolean>); //使用callback异步回调
示例代码
const phoneNumber = "18682358888"; this.tpnsClient.upsertPhoneNumber(phoneNumber).then(()=>{ console.debug("TPush-Demo", "upsertPhoneNumber success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "upsertPhoneNumber fail err:" + JSON.stringify(err)); })this.tpnsClient.upsertPhoneNumber(phoneNumber, (err,) => { if(err){ console.error("TPush-Demo", "upsertPhoneNumber fail err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "upsertPhoneNumber success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
phoneNumber | string | 是 | E.164标准,格式为+[国家或地区码][手机号],例如+8613711112222。SDK 内部加密传输。 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
说明:
手机号格式为
+[国家或地区码][手机号]
,例如+8613711112222(其中前面有一个+号 ,86为国家或地区码,13711112222为手机号)。若绑定的手机号不带国家或地区码,则移动推送下发短信时自动增加+86的前缀;若带上国家或地区码,则按照指定的号码绑定。如需删除绑定的手机号,则需调用 delAccounts
接口并设置 accountType 为 1002
。账号类型解绑
接口说明
对一个或多个账号类型的账号进行解绑。
delAccounts(accountTypeSet:HashSet<number>):Promise<void>; //使用Promise异步回调
示例代码
let accountTypeHashSet: HashSet<number> = new HashSet<number>(); accountTypeHashSet.add(0); this.tpnsClient.delAccounts(accountTypeHashSet).then(()=>{ console.debug("TPush-Demo", "delaccount success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "delaccount fail,err:" + JSON.stringify(err)); });
参数说明
参数名 | 类型 | 必填 | 说明 |
accountTypeSet | HashSet<number> | 是 | 需解绑账号的账号类型 |
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
delAccounts(accountTypeSet:HashSet<number>, callback:Callback<void>); //使用callback异步回调
示例代码
let accountTypeHashSet: HashSet<number> = new HashSet<number>(); accountTypeHashSet.add(0);this.tpnsClient.delAccounts(accountTypeHashSet, (err) => { if(err){ console.error("TPush-Demo", "delaccount fail,err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "delaccount success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
accountTypeSet | HashSet<number> | 是 | 需解绑账号的账号类型。 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
清空所有账号
接口说明
对所有已绑定账号进行解绑。
clearAccounts():Promise<void> //使用Promise异步回调
示例代码
this.tpnsClient.clearAccounts().then(() =>{ console.debug("TPush-Demo", "clearAccount success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "delaccount fail err:" + JSON.stringify(err)); })
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
clearAccounts(callback:Callback<void>) //使用callback异步回调
示例代码
this.tpnsClient.clearAccounts((err) => { if(err){ console.debug("TPush-Demo", "delaccount fail err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "clearAccount success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
标签管理
预设标签
目前移动推送平台提供的预设标签包括:App 版本,系统版本,省份,活跃信息,系统语言,SDK 版本,国家&地区,手机品牌,手机机型。预设标签会在 SDK 内部自动上报。
覆盖多个标签
接口说明
一次设置多个标签,会覆盖这个设备之前设置的标签。
开发者可以针对不同的用户设置标签,然后根据标签名群发通知。 一个应用最多有10000个 tag, 每个 Token 在一个应用下最多100个 tag,如需提高该限制,请联系 在线客服。每个自定义 tag 可绑定的设备 Token 数量无限制,tag 中不准包含空格。
clearAndAppendTags( tags:HashSet<string>):Promise<void>; //使用Promise异步回调
示例代码
let tags = new HashSet<string>(); tags.add("testTag"); tags.add("testTag2"); this.tpnsClient.clearAndAppendTags(tags).then(()=>{ console.debug("TPush-Demo", "clearAndAppendTags success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "clearAndAppendTags fail err:" + JSON.stringify(err)); });
参数说明
参数名 | 类型 | 必填 | 说明 |
tags | HashSet<string> | 是 | 标签名集合,每个标签是一个 String。限制:每个 tag 不能超过50字节(超过会抛弃),不能包含空格(含有空格会删除空格)。最多设置100个 tag,超过部分会抛弃。 |
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
clearAndAppendTags(tags:HashSet<string>,callback:Callback<void>); //使用callback异步回调
示例代码
this.tpnsClient.clearAndAppendTags(tags, (err) => { if(err){ console.error("TPush-Demo", "clearAndAppendTags fail err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "clearAndAppendTags success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
tags | HashSet<string> | 是 | 标签名集合,每个标签是一个 String。限制:每个 tag 不能超过50字节(超过会抛弃),不能包含空格(含有空格会删除空格)。最多设置100个 tag,超过部分会抛弃。 |
callback | Callback<void> | 是 | 回调函数,不能为空 |
新增多个标签
接口说明
如果新覆盖的标签都带有
:
号,例如 test:2, level:2
,则会删除这个设备已绑定的所有 test:*
和 level:*
标签,再新增 test:2
和 level:2
。如果新增的标签有部分不带
:
号,例如 test:2 level
,则会删除这个设备的全部历史标签,再新增 test:2
和 level
标签。说明:
新增的 tags 中,
:
号为后台关键字,请根据具体的业务场景使用。此接口调用的时候需要间隔一段时间(建议大于5s),否则可能造成更新失败。
appendTags(tags:HashSet<string>):Promise<void>; //使用Promise异步回调
示例代码
let tags = new HashSet<string>(); tags.add("testTag"); this.tpnsClient.appendTags(tags).then(()=>{ console.debug("TPush-Demo", "appendTags success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "appendTags fail err:" + JSON.stringify(err)); });
参数说明
参数名 | 类型 | 必填 | 说明 |
tags | HashSet<string> | 是 | 标签名集合,每个标签是一个 String。限制:每个 tag 不能超过50字节(超过会抛弃),不能包含空格(含有空格会删除空格)。最多设置100个 tag,超过部分会抛弃。 |
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
appendTags(tags:HashSet<string>,callback:Callback<void>); //使用callback异步回调
示例代码
let tags = new HashSet<string>(); tags.add("testTag"); this.tpnsClient.appendTags( tags, (err) => { if(err){ console.error("TPush-Demo", "appendTags fail,err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "appendTags success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
tags | HashSet<string> | 是 | 标签名集合,每个标签是一个 String。限制:每个 tag 不能超过50字节(超过会抛弃),不能包含空格(含有空格会删除空格)。最多设置100个 tag,超过部分会抛弃。 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
删除多个标签
接口说明
一次删除多个标签。
delTags(tags:HashSet<string>):Promise<void>; //使用Promise异步回调
示例代码
let delTag = new HashSet<string>(); delTag.add("testTag"); this.tpnsClient.delTags(delTag).then(()=>{ console.debug("TPush-Demo", "delTags success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "delTags fail err:" + JSON.stringify(err)); });
参数说明
参数名 | 类型 | 必填 | 说明 |
tags | HashSet<string> | 是 | 标签名集合,每个标签是一个 String。限制:每个 tag 不能超过50字节(超过会抛弃),不能包含空格(含有空格会删除空格)。最多设置100个 tag,超过部分会抛弃。 |
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
delTags(tags:HashSet<string>, callback:Callback<void>); //使用callback异步回调
示例代码
let delTag = new HashSet<string>(); delTag.add("testTag"); this.tpnsClient.delTags(delTag, (err) => { if(err){ console.error("TPush-Demo", "delTags fail err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "delTags success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
tags | HashSet<string> | 是 | 标签名集合,每个标签是一个 String。限制:每个 tag 不能超过50字节(超过会抛弃),不能包含空格(含有空格会删除空格)。最多设置100个 tag,超过部分会抛弃。 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
清除所有标签
接口说明
清除这个设备的所有标签。
clearTags():Promise<void>;//使用Promise异步回调
示例代码
this.tpnsClient.clearTags().then(()=>{ console.debug("TPush-Demo", "clearTags success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "clearTags fail err:" + JSON.stringify(err)); })
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
clearTags(callback:Callback<void>); //使用callback异步回调
示例代码
this.tpnsClient.clearTags((err) => { if(err){ console.error("TPush-Demo", "clearTags fail err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "clearTags success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
查询标签
接口说明
获取这个设备的标签。
queryTags(offset:number, limit:number):Promise<string>; //使用Promise异步回调
示例代码
this.tpnsClient.queryTags( 0, 100).then((result)=>{ console.debug("TPush-Demo", "queryTags result:" + JSON.stringify(result)); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "queryTags fail err:" + JSON.stringify(err)); })
参数说明
参数名 | 类型 | 必填 | 说明 |
offset | number | 是 | 开始的位置 |
limit | number | 是 | 获取标签的数量,最多为100个 |
返回值
类型 | 说明 |
Promise<string> | 查询结果,返回结果不为空时结果为JSON字符串,为空时为空字符串。 |
接口说明
queryTags(offset:number, limit:number, callback:Callback<string>); //使用callback异步回调
示例代码
this.tpnsClient.queryTags( 0, 100, (err,result) => { if(err){ console.error("TPush-Demo", "queryTags fail err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "queryTags result:" + JSON.stringify(result)); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
offset | number | 是 | 开始的位置 |
limit | number | 是 | 获取标签的数量,最多为100个 |
callback | Callback<boolean> | 是 | 查询结果,返回结果不为空时结果为JSON字符串,为空时为空字符串, err 不为空则表示失败 |
用户属性管理
新增用户属性
接口说明
添加属性:有则覆盖,无则添加。
upsertAttributes(attributes:HashMap<string,string>):Promise<void>; //使用Promise异步回调
示例代码
let attributes: HashMap<string, string> = new HashMap<string, string>(); attributes.set("nickname", "hello"); this.tpnsClient.upsertAttributes(attributes).then(()=>{ console.debug("TPush-Demo", "upsertAttributes success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "queryTags fail err:" + JSON.stringify(err)); });
参数说明
参数名 | 类型 | 必填 | 说明 |
attributes | HashMap<string,string> | 是 | 属性集合,每个属性通过 key-value 标识 |
注意:
属性使用键值对传输,都只接受 string 字符串类型,非空串。
属性个数限制50个。
属性 key,value 长度都限制50个字符以内。
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
upsertAttributes(attributes:HashMap<string,string>, callback:Callback<void>); //使用callback异步回调
示例代码
let attributes: HashMap<string, string> = new HashMap<string, string>(); attributes.set("nickname", "hello");this.tpnsClient.upsertAttributes(attributes, (err) => { if(err){ console.error("TPush-Demo", "queryTags fail err:" + JSON.stringify(err)); }else { console.debug("TPush-Demo", "upsertAttributes success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
attributes | HashMap<string,string> | 是 | 属性集合,每个属性通过 key-value 标识 |
callback | Callback<void> | 是 | 回调函数,不能为空,err 不为空则表示失败 |
注意:
属性使用键值对传输,都只接受 string 字符串类型,非空串。
属性个数限制50个。
属性 key,value 长度都限制50个字符以内。
删除用户属性
接口说明
删除指定的属性
delAttributes(attributesKey:HashSet<string>):Promise<void>; //使用Promise异步回调
示例代码
let attributes = new HashSet<string>(); attributes.add("nickname"); this.tpnsClient.delAttributes(attributes).then(()=>{ console.debug("TPush-Demo", "delAttributes success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "delAttributes fail err:" + JSON.stringify(err)); });
参数说明
参数名 | 类型 | 必填 | 说明 |
attributesKey | HashSet<string> | 是 | 属性集合,每个属性通过 key-value 标识 |
注意:
属性使用键值对传输,都只接受 string 字符串类型,非空串。
属性个数限制50个。
属性 key,value 长度都限制50个字符以内。
返回值
类型 | 说明 |
Promise<void> | 发生错误时抛出异常 |
接口说明
delAttributes(attributesKey:HashSet<string>, callback:Callback<void>); //使用callback异步回调
示例代码
let attributes = new HashSet<string>(); attributes.add("nickname"); this.tpnsClient.delAttributes(attributes, (err) => { if(err){ console.error("TPush-Demo", "delAttributes fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "delAttributes success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
attributesKey | HashSet<string> | 是 | 属性集合,每个属性通过 key-value 标识 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
注意:
属性使用键值对传输,都只接受 string 字符串类型,非空串。
属性个数限制50个。
属性 key,value 长度都限制50个字符以内。
清空已有用户属性
接口说明
删除已设置的所有属性。
clearAttributes():Promise<void>;//使用Promise异步回调
示例代码
this.tpnsClient.clearAttributes().then(()=>{ console.debug("TPush-Demo", "clearAttributes success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "clearAttributes fail err:" + JSON.stringify(err)); })
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
clearAttributes(callback:Callback<void>); //使用callback异步回调
示例代码
this.tpnsClient.clearAttributes((err) => { if(err){ console.error("TPush-Demo", "clearAttributes fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "clearAttributes success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
更新用户属性
接口说明
设置属性(带回调),会覆盖这个设备之前设置的所有属性(即清理并设置)。
clearAndAppendAttributes(attributes:HashMap<string,string>):Promise<void>; //使用Promise异步回调
示例代码
let attributes: HashMap<string, string> = new HashMap<string, string>(); attributes.set("nickname", "haha"); this.tpnsClient.clearAndAppendAttributes(attributes).then(()=>{ console.debug("TPush-Demo", "clearAndAppendAttributes success"); }).catch((err:BusinessError)=>{ console.error("TPush-Demo", "clearAndAppendAttributes fail err:" + JSON.stringify(err)); })
参数说明
参数名 | 类型 | 必填 | 说明 |
attributes | HashMap<string,string> | 是 | 属性集合,每个属性通过 key-value 标识 |
注意:
属性使用键值对传输,都只接受 string 字符串类型,非空串。
属性个数限制50个。
属性 key,value 长度都限制50个字符以内。
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
clearAndAppendAttributes(attributes:HashMap<string,string>, callback:Callback<void>); //使用callback异步回调
示例代码
let attributes: HashMap<string, string> = new HashMap<string, string>(); attributes.set("nickname", "haha"); this.tpnsClient.clearAndAppendAttributes(attributes, (err) => { if(err){ console.error("TPush-Demo", "clearAndAppendAttributes fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "clearAndAppendAttributes success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
attributes | HashMap<string,string> | 是 | 属性集合,每个属性通过 key-value 标识 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
注意:
属性使用键值对传输,都只接受 string 字符串类型,非空串。
属性个数限制50个。
属性 key,value 长度都限制50个字符以内。
角标管理
设置角标
通过该接口可以设置应用角标数
setBadgeNumber(badgeNumber:number):Promise<void>; //使用Promise异步回调
示例代码
const bageNumbber = 1; this.tpnsClient.setBadgeNumber(bageNumbber).then(() => { console.debug("TPush-Demo", "setBadge success"); }).catch((err: Error) => { console.debug(TAG, "setBadge fail err:" + JSON.stringify(err)); });
参数说明
参数名 | 类型 | 必填 | 说明 |
badgeNumber | number | 是 | 角标数 |
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
setBadgeNumber(badgeNumber:number, callback:Callback<void>);//使用callback异步回调
示例代码
const bageNumbber = 1; this.tpnsClient.setBadgeNumber(bageNumbber,(err)=>{ if(err){ console.debug(TAG, "setBadge fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "setBadge success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
badgeNumber | number | 是 | 角标数 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
清除角标
接口说明
清除应用角标。
clearBadge():Promise<void>;//使用Promise异步回调
示例代码
this.tpnsClient.clearBadge().then(() => { console.debug("TPush-Demo", "clearBadge success"); }).catch((err: Error) => { console.debug(TAG, "clearBadge fail err:" + JSON.stringify(err)); });
返回值
类型 | 说明 |
Promise<void> | 发生错误时会抛出异常 |
接口说明
clearBadge(callback:Callback<void>); //使用callback异步回调
示例代码
this.tpnsClient.clearBadge((err)=>{ if(err){ console.debug(TAG, "clearBadge fail err:" + JSON.stringify(err)); }else{ console.debug("TPush-Demo", "clearBadge success"); } });
参数说明
参数名 | 类型 | 必填 | 说明 |
callback | Callback<void> | 是 | 回调函数,不能为空, err 不为空则表示失败 |
接口关联的类
以下为移动推送对外提供接口中关联的类的属性和方法的说明。
TPNS.ConfigOption
参数名 | 类型 | 必填 | 说明 |
accessKey | string | 是 | 在移动推送TPNS控制台创建应用时生成的AccessKey |
debugMode | boolean | 否 | debug模式,默认关闭 |
debugLevel | 否 | 移动推送SDK日志输出等级,默认等级TPNS.LogLevel.DEBUG | |
keepAliveInterval | number | 否 | 移动推送SDK长链接心跳间隔,单位秒,默认270秒 |
host | string | 否 | 移动推送SDK接入点,默认接入点广州集群,非广州集群需要配置 |
TPNS.LogLevel
参数名 | 说明 |
INFO | debugMode开启时,logLevel设置为INFO,输出移动推送SDK INFO、WARN及ERROR级别日志 |
WARN | debugMode开启时,logLevel设置为WARN,输出移动推送SDK WARN及ERROR级别日志 |
ERROR | debugMode开启时,logLevel设置为ERROR,输出移动推送SDK ERROR级别日志 |
TPNS.TPushClient
接口描述 | 说明 |
移动推送 SDK 注册接口,通过此接口可以获取到移动推送的设备token,用于后台触发推送 | |
| |
移动推送 SDK 注册接口,此接口在注册时一起绑定一个账号,此接口可以获取到移动推送的设备token | |
| |
不再需要接收推送时,可以取消注册 ,即反注册(一旦设备反注册,直到这个设备重新注册成功期间内,下发的消息该设备都无法收到)。 | |
| |
添加或更新账号。若原来没有该类型账号,则添加;若原来有,则覆盖。可以同时添加多个账号,一个账号对应一个账号类型 | |
| |
添加或更新手机号码。若原来没有绑定手机号码,则绑定;若原来有,则覆盖 | |
| |
对一个或多个账号类型的账号进行解绑。 | |
| |
对所有已绑定账号进行解绑 | |
| |
新增多个标签 | |
| |
一次设置多个标签,会覆盖这个设备之前设置的标签。 | |
| |
一次删除多个标签 | |
| |
清除这个设备的所有标签 | |
| |
获取这个设备的标签 | |
| |
給该设备添加属性,有则覆盖,无则添加 | |
| |
删除该设备指定的属性 | |
| |
删除该设备已设置的所有属性。 | |
| |
设置属性,会覆盖这个设备之前设置的所有属性(即清理并设置)。 | |
| |
设置应用角标数,会覆盖当前应用已有的角标数 | |
| |
清除应用角标数 | |
| |
增加本地通知 | |
| |
清除本地通知 | |
根据通知id 取消当前应用通知栏中某个通知 | |
| |
取消当前应用所有通知栏所有的通知 | |
| |
进入页面时oncreate,onNewWant , 根据want 获取是否是通过通知点击,是则返回通知消息,否则返回空 | |
设置消息接收器,用于接收透传消息、自建通道通知消息抵达、展示回调 |
TPNS.Account
参数名 | 类型 | 必填 | 说明 |
account | string | 是 | 账号 |
accountType | number | 否 |
TPNS.NotificationMessage
参数名 | 类型 | 必填 | 说明 |
msgId | string | 是 | 通知消息的 |
title | string | 否 | 通知标题,当为鸿蒙厂商通道的通知标题为空 |
content | string | 否 | 通知内容,当为鸿蒙厂商通道的通知内容为空 |
customContent | string | 否 | 附加参数 |
pushChannel | 是 | 通知触发渠道 | |
templatedId | string | 否 | 通知模板id |
traceId | string | 否 | 通知traceId |
TPNS.MessagePushChannel
参数名 | 账号类型之值 | 说明 |
LOCAL | 99 | 本地通知 |
TPNS | 100 | 移动推送自建通道 |
HARMONY | 108 | 鸿蒙系统通道 |
TPNS.PushMessage
移动推送透传消息,透传消息仅当消息通过移动推送通道下发。
参数名 | 类型 | 必填 | 说明 |
msgId | string | 是 | 消息ID |
title | string | 否 | 消息标题,点击鸿蒙厂商通道的标题为空 |
customContent | string | 否 | 附加参数 |
templatedId | string | 否 | 模板id |
traceId | string | 否 | trace ID |
TPNS.LocalMessage
用于添加本地消息时,需要使用到的本地消息体。
参数名 | 类型 | 必填 | 说明 |
notifyId | string | 否 | 通知id,设置SDK内部会根据时间生成 |
threadId | string | 否 | 通知分组,不传则使用默认分组 |
traceId | string | 否 | 附加参数 |
type | 是 | 模板id | |
notificationSlotType | 否 | 通知slot 类型,参考notificationManager.SlotType
已有如下值
0 - UNKNOWN_TYPE 未知类型。
1 - SOCIAL_COMMUNICATION 社交通信
2 - SERVICE_INFORMATION 服务提醒。
3 - CONTENT_INFORMATION 内容资讯。
4 - LIVE_VIEW 实况窗。(预留能力,暂未支持)。
5 - CUSTOMER_SERVICE 客服消息。该类型用于用户与商家之间的客服消息,需由用户主动发起。 | |
isAlertOnce | boolean | 否 | 设置是否仅有一次此通知提醒。 |
largetIcon | string | 否 | 通知大图标。可选字段,图像像素的总字节数不超过100KB。实际显示效果依赖于设备能力和通知中心UI样式。 |
largetIconType | number | 否 | 大图标图片类型:
0 本地图片资源文件名,图片应位于media目录下
1 图片url |
title | string | 是 | 本地通知标题 |
content | string | 是 | 本地通知内容 |
additionalText | string | 否 | 通知概要内容,是对通知内容对补充,不传则使用content代替 |
inlines | string[] | 否 | 多行类型通知,最多支持3行内容,并且每行内容不能为空,如果为空则弹出普通通知。 |
badgeNumber | number | 否 | 本地通知为通知消息时生效,要增加的角标数,大于等于0, 不传角标数不变 |
date | number | 否 | 本地通知触发的日期 |
hour | number | 否 | 在触发本地通知日期前提下,当天允许触发本地通知开启的小时, 24小时制 |
min | number | 否 | 在触发本地通知日期前提下,当天允许触发本地通知的分钟,与hour字段配合使用 |
actionType | 是 | 点击通知后触发的行为 打开应用首页或打开应用自定义页面 | |
action | string | 否 | 当actionType为打开应用自定义页面时,字段uri和action至少填写一个,优先使用action字段 |
uri | string | 否 | 应用内置页面ability对应的uri,ur对象内部结构请参见
skills标签。当actionType为打开自定义页面时,字段uri和action
至少填写一个。当存在多个Ability时,分别填写不同
Ability的action和uri,优先使用action查找对应的应用内置页面 |
customContent | string | 否 | 附加参数 |
ttl | number | 否 | 消息过期时间,默认72h |
showMode | 否 | 通知展示模式,默认都展示 或只有后台才展示 |
TPNS.LocalMessageType
本地通知类型
参数名 | 说明 |
NOTIFICATION | 通知 |
PUSHMESSAGE | 透传消息 |
TPNS.LocalMessageActionType
本地通知为通知时,actionType的定义。
参数名 | 说明 |
OPEN_APP | 打开应用首页 |
OPEN_CUSTOM_ABILITY | 打开自定义页面 |
TPNS.LocalMessageShowMode
本地通知为通知时,通知的展示模式。
参数名 | 说明 |
DEFAULT | 默认,应用在前台和后台时本地通知都可以展示 |
BACKGROUND | 应用在后台时展示通知。 注意: 本地通知依赖app进程存活,app进程被杀掉时本地通知不会被触发。 |
TPNS.MessageReceiver
设置推送消息回调接口的对象的接口类,开发者自行实现该接口类才能收到推送消息的回调。
回调方法名 | 说明 |
onNotificationDeleted(err:Error,notificationMessage:TPNS.NotificationMessage) | 当通知被移除时回触发此回调方法 注意: 因为系统限制,当前只有本地通知和移动推送通道展示的通知被清除时才会触发此回调方法,并且 要求应用进程没有被系统杀掉。 |
onNotificationShow(err:Error notificationMessage:TPNS.NotificationMessage) | 本地推送通知和移动推送通道展示的通知会触发此回调,err为空则表示展示成功 |
onTextMessage(err:Error,pushMessage:TPNS.PushMessage) | 透传消息收到时会触发此回调 |