更新记录
1.0.0(2026-07-01)
新增
- 跨平台通知栏 UTS 插件:Android、iOS、HarmonyOS 三端统一公开 API。
- 通知权限申请、普通/大文本/大图/进度通知,以及更新、完成、取消。
- 点击回调(
onNotificationClick)、打开指定页面、定时/重复通知、通知分组。 - 动作按钮、静默通知、自动消失、自定义声音与震动节奏等样式参数。
- Android 动作按钮兼容 UTSArray 桥接解析,带动作按钮的通知自动使用展开样式。
- Android 声音/震动按
soundPath、vibratePattern、silent自动派生渠道,发送后主动提醒兜底。 - Android、iOS、HarmonyOS 原生实现与 UTS 类型定义。
- uni-app / uni-app x 双端示例页(含分组、样式、点击等 11 个场景)与使用文档(三端能力矩阵、自定义基座说明)。
平台兼容性
uni-app(5.06)
| Vue2 | Vue2插件版本 | Vue3 | Vue3插件版本 | Chrome | Safari | app-vue | app-vue插件版本 | app-nvue | app-nvue插件版本 | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | 1.0.0 | √ | 1.0.0 | × | × | √ | 1.0.0 | √ | 1.0.0 | 5.0 | 12 | √ |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(5.06)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | 5.0 | 12 | √ | - |
xview-notification
跨平台通知栏提示 UTS 插件,Android、iOS、HarmonyOS 三端保持同一套公开 API,支持普通通知、大文本通知、进度通知、点击回调、定时/重复通知、大图通知、通知分组、通知更新和取消。不同系统的通知能力不完全一致,部分能力会在 iOS 或 HarmonyOS 上按平台规则降级。
权限
Android 已在 AndroidManifest 中声明:
android.permission.POST_NOTIFICATIONSandroid.permission.VIBRATE
Android 13 及以上、iOS、HarmonyOS 都建议发送前先调用 requestNotificationPermission。iOS/HarmonyOS 的通知开关查询是异步能力,isNotificationEnabled 返回原生层最近一次缓存状态。
使用示例
import {
requestNotificationPermission,
sendSimpleNotification,
sendNotification,
sendProgressNotification,
scheduleNotification,
sendRepeatingNotification,
onNotificationClick,
updateProgress,
completeProgress,
cancelAllNotifications
} from '@/uni_modules/xview-notification'
onNotificationClick((event) => {
console.log('notification click', event.id, event.type, event.target, event.actionId)
// open-page 需在 App 层自行跳转,插件内不调用 uni.navigateTo
if (event.type === 'open-page' && event.target) {
uni.navigateTo({ url: event.target })
}
})
requestNotificationPermission(
() => {
const id = sendSimpleNotification('标题', '通知内容')
console.log('notification id', id)
},
() => {
console.log('通知权限未开启')
}
)
const bigId = sendNotification({
channelId: 'xview_big_text',
channelName: '大文本通知',
title: '任务完成',
content: '展开查看详情',
bigText: '这里是更长的通知内容。',
priority: 'high',
vibrate: true
})
const progressId = sendProgressNotification('处理中', '当前进度 10%', 10, 100)
updateProgress(progressId, 60, 100)
completeProgress(progressId)
scheduleNotification({
title: '定时提醒',
content: '5 秒后触发',
delay: 5000
})
sendRepeatingNotification({
title: '重复提醒',
content: '每分钟触发一次',
repeatInterval: 60 * 1000
})
cancelAllNotifications()
自定义图标与固定 ID
sendSimpleNotification('标题', '带图标的通知', '/static/logo.png')
sendNotification({
id: 9001,
title: '固定 ID 通知',
content: '再次发送会覆盖同 ID 通知',
iconPath: '/static/logo.png'
})
cancelNotification(9001)
样式与行为参数
sendNotification({
title: '样式示例',
content: '副标题 + 强调色 + 仅提醒一次',
subText: '业务分类',
bigTitle: '展开后的大标题',
color: 0xff0ea5e9,
showWhen: true,
onlyAlertOnce: true,
priority: 'high',
ongoing: true,
autoCancel: false
})
sendNotification({
title: '静默通知',
content: '不响铃、不震动',
silent: true
})
sendNotification({
title: '自动消失',
content: '5 秒后自动取消',
timeoutAfter: 5000
})
sendNotification({
title: '默认提示音',
content: '使用系统默认通知提示音',
soundPath: 'default'
})
sendNotification({
title: '自定义震动',
content: 'Android 支持自定义震动节奏',
vibrate: true,
vibratePattern: [0, 180, 80, 260, 80, 360]
})
点击行为 type
// 仅拉起应用(默认)
sendNotification({ title: '打开应用', content: '点击后回到前台', type: 'open-app' })
// 拉起应用并跳转页面,target 为页面路径
sendNotification({
title: '打开页面',
content: '点击后跳转到业务页',
type: 'open-page',
target: '/pages/index/index'
})
// 点击后通过 onNotificationClick 回调 target 字符串
sendNotification({
title: '点击回调',
content: '在 callback 中处理业务逻辑',
type: 'open-callback',
target: 'order:10086'
})
// 动作按钮会通过 onNotificationClick 回传 actionId
sendNotification({
title: '订单待处理',
content: '在通知上直接处理',
type: 'open-callback',
target: 'order:10086',
actions: [
{ id: 'view', title: '查看', type: 'open-page', target: '/pages/demo/open-page' },
{ id: 'confirm', title: '确认', type: 'open-callback', target: 'order:10086:confirm' }
]
})
不确定进度
const id = sendProgressNotification('同步中', '正在处理...', 0, 100, true)
updateProgress(id, 50, 100)
completeProgress(id)
定时 triggerAt 与 repeatType
// 指定绝对触发时间(毫秒时间戳)
scheduleNotification({
title: '预约提醒',
content: '在指定时间点触发',
triggerAt: Date.now() + 10 * 1000
})
// 使用 repeatType 快捷周期(minute/hour/day/week)
sendRepeatingNotification({
title: '每小时提醒',
content: 'repeatType 示例',
delay: 3000,
repeatType: 'hour'
})
cancelScheduledNotification(scheduledId)
updateNotification
updateNotification(progressId, {
title: '下载完成',
content: '文件已保存',
bigText: '点击查看详情',
progressCurrent: 100,
progressMax: 100
})
示例工程
| 框架 | 首页 | 示例目录 |
|---|---|---|
| uni-app | pages/index/index.vue |
pages/notification/*.vue |
| uni-app x | pagesx/index/index.uvue |
pagesx/notification/*.uvue |
三端能力对齐
| 能力 | Android | iOS | HarmonyOS |
|---|---|---|---|
| 公开 API | 完整对齐 | 完整对齐 | 完整对齐 |
| 普通通知 | NotificationCompat 原生通知 |
UserNotifications 本地通知 |
notificationManager 基础文本通知 |
| 声音/震动 | 支持 soundPath、vibrate、vibratePattern,并按渠道配置自动派生实际 channel |
支持系统通知声音或 bundle 声音;震动遵循 iOS 通知声音/系统设置策略 | 参数保留,基础通知发布时由系统槽位和用户设置决定 |
| 静默通知 | 支持,且不会主动播放声音或震动 | 支持,不设置通知声音 | 参数保留,按 HarmonyOS 系统能力降级 |
| 进度通知 | 系统进度条 | 正文文本进度 | 正文文本进度 |
| 大文本 | 原生大文本样式 | 正文展开文本 | 正文文本降级 |
| 大图 | 原生大图样式 | 通知附件 | 正文提示图片路径 |
| 分组 | 原生分组和摘要 | threadIdentifier 分组 |
字段保留,基础文本降级 |
| 动作按钮 | 原生动作按钮,点击回传 actionId |
原生动作按钮,点击回传 actionId |
动作标题降级到正文展示 |
| 点击事件 | 支持 onNotificationClick |
支持 onNotificationClick |
API 保留,当前不产生系统点击 payload |
| 定时通知 | AlarmManager |
UNTimeIntervalNotificationTrigger |
进程内 timer 降级 |
| 重复通知 | 支持自定义间隔 | 支持,系统要求最小 60 秒 | 进程内 timer 降级 |
HarmonyOS 当前实现以 API 对齐和基础文本通知为主,适合先保证业务代码跨端可调用;需要强交互通知时优先以 Android/iOS 真机能力为准。
API
| 方法 | 说明 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
requestNotificationPermission(success, fail) |
申请通知权限 | 支持 | 支持 | 支持 |
isNotificationEnabled() |
检查应用通知是否可用 | 支持 | 支持 | 支持 |
openNotificationSettings() |
打开应用通知设置页 | 支持 | 支持 | 支持(应用详情页) |
sendNotification(options) |
发送通知,返回通知 ID,失败返回 -1 |
支持 | 支持 | 基础文本通知 |
sendSimpleNotification(title, content, iconPath?) |
发送普通通知 | 支持 | 支持(忽略小图标) | 支持(忽略小图标) |
sendProgressNotification(title, content, current, total, indeterminate?) |
发送进度通知 | 支持 | 文本进度 | 文本进度 |
onNotificationClick(callback) |
监听通知点击事件 | 支持 | 支持 | API 保留,当前不触发 |
offNotificationClick() |
移除通知点击监听 | 支持 | 支持 | 支持 |
scheduleNotification(options) |
定时通知 | 支持 | 支持 | 进程内 timer 降级 |
sendRepeatingNotification(options) |
重复通知 | 支持 | 支持(最小 60 秒) | 进程内 timer 降级 |
cancelScheduledNotification(id) |
取消定时或重复通知 | 支持 | 支持 | 支持 |
updateNotification(id, options) |
更新标题、内容、进度或大文本 | 支持 | 支持 | 支持 |
updateProgress(id, current, total?) |
更新进度通知 | 支持 | 支持 | 支持 |
completeProgress(id) |
将进度通知置为完成 | 支持 | 支持 | 支持 |
cancelNotification(id) |
取消指定通知 | 支持 | 支持 | 支持 |
cancelAllNotifications() |
取消全部通知 | 支持 | 支持 | 支持 |
options
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
channelId |
string |
xview_default |
Android 通知渠道 ID;iOS/HarmonyOS 保留字段 |
channelName |
string |
Xview 通知 |
Android 通知渠道名称;HarmonyOS 可作为附加文本兜底 |
title |
string |
必填 | 通知标题 |
content |
string |
必填 | 通知内容 |
iconPath |
string |
- | 通知小图标本地路径,Android 支持 |
type |
open-app/open-page/open-callback |
open-app |
点击行为 |
target |
string |
- | 页面路径或回调携带数据 |
id |
number |
随机 | 通知 ID,相同 ID 会覆盖 |
color |
number |
- | 强调色,如 0xff0ea5e9,Android 支持 |
subText |
string |
- | 副标题 |
showWhen |
boolean |
true |
是否显示时间,Android 支持 |
priority |
min/low/default/high/max |
default |
通知优先级,Android 支持完整优先级,iOS 映射为通知打断级别 |
ongoing |
boolean |
false |
是否常驻,Android/HarmonyOS 支持 |
autoCancel |
boolean |
true |
点击后是否自动取消,Android/HarmonyOS 支持 |
onlyAlertOnce |
boolean |
false |
相同内容是否只提醒一次,Android 支持 |
vibrate |
boolean |
false |
是否震动,Android 支持;iOS/HarmonyOS 受系统通知策略影响 |
vibratePattern |
number[] |
- | 自定义震动节奏,Android 支持 |
silent |
boolean |
false |
静默通知,不主动响铃或震动 |
timeoutAfter |
number |
- | 自动消失时间,单位毫秒 |
soundPath |
string |
- | default 使用系统默认通知音;Android 支持文件路径或 raw 资源名,iOS 支持 bundle 声音名 |
actions |
{ id, title, type?, target? }[] |
- | Android/iOS 为通知动作按钮并回传 actionId;HarmonyOS 降级为正文提示。Android/iOS 通常需要展开通知后才显示按钮 |
showProgress |
boolean |
false |
是否显示进度,Android 为系统进度条,iOS/HarmonyOS 为正文文本 |
progress |
{ current, total, indeterminate? } |
- | 进度配置 |
bigText |
string |
- | 大文本展开内容,HarmonyOS 降级为正文 |
bigTitle |
string |
- | 大文本样式标题,Android/iOS 使用更完整 |
summaryText |
string |
- | 摘要说明 |
bigImagePath |
string |
- | 大图通知图片路径,Android/iOS 支持,HarmonyOS 降级为正文路径 |
groupId |
string |
- | 通知分组 ID,Android/iOS 支持,HarmonyOS 保留字段 |
groupTitle |
string |
- | 分组摘要标题,Android/iOS 支持 |
groupSummary |
string |
- | 分组摘要内容,Android/iOS 支持,HarmonyOS 可作为正文 |
isGroupSummary |
boolean |
false |
是否为分组摘要通知,Android/iOS 支持 |
delay |
number |
1000 |
定时通知延迟毫秒数 |
triggerAt |
number |
- | 定时通知触发时间戳,毫秒 |
repeatType |
minute/hour/day/week |
- | 重复周期快捷值 |
repeatInterval |
number |
- | 自定义重复间隔毫秒 |
Android 8.0+ 的声音和震动由通知渠道控制,同一 channelId 首次创建后系统会固定该渠道配置。本插件会在 soundPath、vibratePattern 或 silent 不同时自动派生实际渠道,并在通知发送成功后主动触发一次声音/震动兜底,避免复用旧渠道导致声音或震动不生效。
修改 Android/iOS/HarmonyOS 原生桥接代码后,需要重新制作或更新自定义调试基座;只热同步页面文件不会更新已打入基座的 UTS 原生插件代码。

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(0)
下载 8
赞赏 0
下载 12372319
赞赏 1927
赞赏
京公网安备:11010802035340号