更新记录
1.5.0(2023-07-08)
本次主要更新: 1.修复 来多条通知过快,语音播报错误的bug
1.4.0(2022-07-04)
本次主要更新: 1.修复 提交到appstore,提示Asset validation failed (90085)问题
1.3.0(2022-06-24)
本次主要更新: 1.修复播报0.1的时候,0不能播报
查看更多平台兼容性
Android | iOS |
---|---|
× | 适用版本区间:10 - 16 |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
KJ-NotificationService
前台后台离线推送语言播报、到账xx元
ios 注意事项 更多教程: https://docs.qq.com/doc/DWkFJTlZXWUhzT1pU
1.配置扩展
需要在 主目录->nativeplugins->KJ-NotificationService 下配置添加ios-extension.json和ios-notificationService.mobileprovision文件
ios-extension.json文件配置参考 示列项目
比如主工程Bundle ID为:com.xxxx.xxxx
分享扩展的Bundle ID 和 App Groups Bundle ID 需要开苹果开发者官网配置
{
"notificationService.appex": {
"identifier": "com.xxxx.xxxx.noti",
"profile": "ios-notificationService.mobileprovision",
"plists": {
"KJGroupIdentifier": "group.com.xxxx.xxxx.noti"
},
"entitlements": {
"com.apple.security.application-groups": ["group.com.xxxx.xxxx.noti"]
}
}
}
2.添加音频文件
需要在 主目录->nativeplugins->KJ-AddAudios->添加音频文件
具体用法,下载示列工程
3.配置manifest.json
/* ios打包配置 */
"ios" : {
"capabilities" : {
"entitlements" : {
"com.apple.security.application-groups" : ["group.com.xxxx.xxxx.noti"]
},
}
},
4.推送平台,推送的时候
ios配置:mutable-content:1,设置之后才能触发通知扩展
在uniPush推送平台上设置,创建推送->通知信息/透传信息->ios配置->多媒体推送打勾,就会默认配置mutable-content
个推服务器端推送,配置 mutable-content:1
{
"request_id":"请求id",
"settings":{
"ttl":3600000
},
"push_message":{
"notification":{
"title":"请填写通知标题",
"body":"请填写通知内容",
"click_type":"url",
"url":"https//:xxx"
}
},
"push_channel":{
"ios":{
"aps":{
"alert":{
"title":"标题",
"body":"收钱吧到账11元"
},
"mutable-content":1 //设置之后才能触发通知扩展
}
}
}
}
导入插件
const KJNotificationService = uni.requireNativePlugin('KJ-NotificationService');
使用
<template>
<view class="content">
<!-- <input placeholder="请输入内容" /> -->
<button type="primary" @click="turnOn()">开启语音播报</button>
<button type="primary" @click="closure()">关闭语音播报</button>
<button type="primary" @click="contentToAudio()">文本生成音频或播放</button>
</view>
</template>
<script>
const KJNotificationService = uni.requireNativePlugin('KJ-NotificationService');
export default {
data() {
return {
title: 'KJ-NotificationService'
}
},
onLoad() {
console.log("onLoad")
},
onReady() {
this.turnOn();
},
methods: {
turnOn() {
/**
* audios 根据推送body字符串,识别播放音频
* */
var dic = {
"GroupIdentifier": "group.com.kj.KJDocument.share",
"rate": 2.0, //语音播报速率 1为正常
"keyWords": [{ //根据关键词来,来判断是否要播放音频,不存在则不播放,显示系统声音
"name": "到账"
}],
"audios": [{
"type": "start", //数字前面的内容
"value": [{
"name": "收钱吧到账",
"fileName": "pre.mp3"
}]
},
{
"type": "number", //数字内容,name字段不可以修改,否则不能识别中文数字
"value": [{
"name": "零",
"fileName": "0.mp3"
},
{
"name": "一",
"fileName": "1.mp3"
},
{
"name": "二",
"fileName": "2.mp3"
},
{
"name": "三",
"fileName": "3.mp3"
},
{
"name": "四",
"fileName": "4.mp3"
},
{
"name": "五",
"fileName": "5.mp3"
},
{
"name": "六",
"fileName": "6.mp3"
},
{
"name": "七",
"fileName": "7.mp3"
},
{
"name": "八",
"fileName": "8.mp3"
},
{
"name": "九",
"fileName": "9.mp3"
},
{
"name": "十",
"fileName": "10.mp3"
},
{
"name": "百",
"fileName": "hundred.mp3"
},
{
"name": "千",
"fileName": "thousand.mp3"
},
{
"name": "万",
"fileName": "ten_thousand.mp3"
},
// {
// "name": "亿",
// "fileName": "ten_thousand.mp3"//由于收钱吧app,没有提供亿的音频,推送可以限制最大99999999
// },
{
"name": ".",
"fileName": "dot.mp3"
},
]
},
{
"type": "end", //数字后面的内容
"value": [{
"name": "元",
"fileName": "yuan.mp3"
}]
}
]
}
console.log(dic);
KJNotificationService.init(dic);
},
closure() {
var dic = {
"GroupIdentifier": "group.com.kj.KJDocument.share",
"rate": 2.0, //语音播报速率 1为正常
"keyWords": [],
"audios": []
}
KJNotificationService.init(dic);
},
contentToAudio() {
KJNotificationService.contentToAudio({
"GroupIdentifier": "group.com.kj.KJDocument.share",
"content": "收钱吧到账1.01元", //msg.content,
"isAutoPlay": true
}, (res) => {
console.log(res);
var type = res.type;
if (type == "generateAudio") {
console.log("生成音频");
} else if (type == "playStart") {
console.log("播放开始");
} else if (type == "playFinish") {
console.log("播放完成");
} else if (type == "playError") {
console.log("播放错误");
} else {
console.log("异常");
}
});
}
}
}
</script>
<style>
</style>