var mtpushModule = uni.requireNativePlugin("EL-MTPush");
开启 debug 模式,默认是关闭
- true - 开启,false - 关闭
mtpushModule.setLoggerEnable(true);
设置数据中心, 在初始化函数(initPushService)之前设置。
- 数据中心的名称, 可不设置,不设置默认为新加坡数据中心
- android 如果调用该接口设置,那就不会使用package.json中的(MTPUSH_SITENAME_ANDROID)配置。
mtpushModule.setSiteName("Singapore");
调用此 API 来取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串
- CALLBACK
参数名称 | 参数类型 | 参数说明 |
---|---|---|
code | number | 状态码 0 - 成功, 1011 - iOS模拟器调用会报此错误 |
registerID | string | 返回的 registrationID |
mtpushModule.getRegistrationID(result=>{
let registerID = result.registerID
})
跳转至系统设置页面
- CALLBACK
参数名称 | 参数类型 | 参数说明 |
---|---|---|
code | number | 0 - 成功 1 - 失败 |
mtpushModule.openSettingsForNotification((result)=>{
let code = result.code
})
初始化SDK iOS 说明:如果在mainfest.json里 将MTPUSH_DEFAULTINITJPUSH_IOS值配置为"true",插件内部将默认初始化MTPush,用户则不需要调用该初始化方法。
mtpushModule.initPushService()
- CALLBACK
参数名称 | 参数类型 | 参数说明 |
---|---|---|
connectEnable | boolean | true - 已连接, false - 未连接 |
mtpushModule.addConnectEventListener(result=>{
let connectEnable = result.connectEnable
})
通过CALLBACK 的 notificationEventType字段 区分 是 通知收到 还是 点击通知
- CALLBACK
参数名称 | 参数类型 | 参数说明 |
---|---|---|
messageID | string | 唯一标识通知消息的 ID |
title | string | 对应 Portal 推送通知界面上的“通知标题”字段 |
content | string | 对应 Portal 推送通知界面上的“通知内容”字段 |
badge | string | 对应 Portal 推送通知界面上的可选设置里面的“badge”字段 (ios only) |
ring | string | 推送通知界面上的可选设置里面的“sound”字段 (ios only) |
extras | dictionary | 对应 Portal 推送消息界面上的“可选设置”里的附加字段 |
iOS | dictionary | 对应原生返回的通知内容,如需要更多字段请查看该字段内容 |
android | dictionary | 对应原生返回的通知内容,如需要更多字段请查看该字段内容 |
notificationEventType | string | 分为notificationArrived和notificationOpened两种 |
mtpushModule.addNotificationListener(result=>{
let notificationEventType = result.notificationEventType
let messageID = result.messageID
let title = result.title
let content = result.content
let extras = result.extras
})
监听 Portal 发送的自定义消息
- CALLBACK
参数名称 | 参数类型 | 参数说明 |
---|---|---|
messageID | string | 唯一标识通知消息的 ID |
content | string | 对应 Portal 推送通知界面上的“通知内容”字段 |
extras | dictionary | 对应 Portal 推送消息界面上的“可选设置”里的附加字段 |
mtpushModule.addCustomMessageListener(result=>{
let messageID = result.messageID
let content = result.content
let extras = result.extras
})
- CALLBACK
参数名称 | 参数类型 | 参数说明 |
---|---|---|
code | number | 请求状态码 0 - 成功 |
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
tags | StringArray | 执行tag数组操作时返回 |
tag | string | 执行查询指定tag(queryTag)操作时会返回 |
tagEnable | boolean | 执行查询指定tag(queryTag)操作时会返回是否可用 |
alias | string | 对alias进行操作时返回 |
mtpushModule.addTagAliasListener(result=>{
let code = result.code
let sequence = result.sequence
let tags = result.tags
let tag = result.tag
let tagEnable = result.tagEnable
let alias = result.alias
})
这个接口是增加逻辑,而不是覆盖逻辑
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
tags | StringArray | string类型的数组 |
mtpushModule.addTags({
'tags':['beauty','rich'],
'sequence': 1
})
需要理解的是,这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
tags | StringArray | string类型的数组 |
mtpushModule.updateTags({
'tags':['beauty','rich'],
'sequence': 1
})
删除指定标签
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
tags | StringArray | string类型的数组 |
mtpushModule.deleteTags({
'tags':['beauty','rich'],
'sequence': 1
})
清除所有标签
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
mtpushModule.cleanTags({
'sequence': 1
})
查询指定 tag 与当前用户绑定的状态
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
tag | string | 需要查询的标签 |
mtpushModule.queryTag({
'tag':'beauty',
'sequence': 1
})
查询所有标签
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
mtpushModule.getAllTags({
'sequence': 1
})
每次调用设置有效的别名,覆盖之前的设置
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
alias | string | 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.| |
mtpushModule.setAlias({
'alias' : 'coder',
'sequence': 1
})
删除别名
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
mtpushModule.deleteAlias({
'sequence': 1
})
删除别名
- Object
参数名称 | 参数类型 | 参数说明 |
---|---|---|
sequence | number | 请求时传入的序列号,会在回调时原样返回 |
mtpushModule.queryAlias({
'sequence': 1
})
本接口用于配合 JPush 提供的服务器端角标功能. iOS:该功能解决的问题是, 服务器端推送 APNs 时, 并不知道客户端原来已经存在的角标是多少, 指定一个固定的数字不太合理.
- 通过本 API 把当前客户端(当前这个用户的) 的实际 badge 设置到服务器端保存起来;
- 调用服务器端 API 发 APNs 时(通常这个调用是批量针对大量用户), 使用 "+1" 的语义, 来表达需要基于目标用户实际的 badge 值(保存的) +1 来下发通知时带上新的 badge 值;
Android:仅支持华为
mtpushModule.setBadge(10)
请参考EngageLab官网