更新记录
1.0.0(2022-08-10)
新版首发
平台兼容性
Android | iOS |
---|---|
× | 适用版本区间:10 - 17 |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在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-Notification
本地推送通知完整版、自定义铃声、添加附件、定时推送、重复规则推送、位置推送、可用于做闹钟提醒、监听收到或打开通知(ios)
使用
<template>
<view class="content">
<button type="primary" @click="addLocalNotification">添加本地通知</button>
<button type="primary" @click="willPresentNotification">监听收到通知</button>
<button type="primary" @click="didReceiveNotificationResponse">监听通知打开</button>
<view class="text">已经展示的通知</view>
<button type="primary" @click="removeAllDeliveredNotifications">移除所有</button>
<button type="primary" @click="removeDeliveredNotificationsWithIdentifiers">移除某个</button>
<button type="primary" @click="getDeliveredNotificationsWithCompletionHandler">获取所有</button>
<view class="text">还未展示的通知</view>
<button type="primary" @click="removeAllPendingNotificationRequests">移除所有</button>
<button type="primary" @click="removePendingNotificationRequestsWithIdentifiers">移除某个</button>
<button type="primary" @click="getPendingNotificationRequestsWithCompletionHandler">获取所有</button>
</view>
</template>
<script>
const KJNotification = uni.requireNativePlugin('KJ-Notification');
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
this.willPresentNotification();
this.didReceiveNotificationResponse();
},
methods: {
willPresentNotification() {
KJNotification.willPresentNotification((res) => {
uni.showModal({
title: '收到通知',
content: JSON.stringify(res),
showCancel: false,
success: function(res) {}
});
});
},
didReceiveNotificationResponse() {
KJNotification.didReceiveNotificationResponse((res) => {
uni.showModal({
title: '通知打开',
content: JSON.stringify(res),
showCancel: false,
success: function(res) {}
});
});
},
addLocalNotification() {
var dic = {
"content": {
"title": "通知标题",
"subtitle": "通知副标题",
"body": "通知内容",
"badge": 1,
"categoryIdentifier": "categoryIdentifier",
"userInfo": {
"test": "自定义"
},
"sound": {
"soundType": "normal", //normal critical(ios12及以上)
"soundPath": plus.io.convertLocalFileSystemURL("static/1.mp3"),
//"volume": 1.0 //soundType 为critical 有效 0.0-1.0
},
"attachments": [{ //附件 图片10M 音频5M 视频50M //添加多个只能显示第一个
"identifier": "identifier",
"filePath": plus.io.convertLocalFileSystemURL("static/logo.png")
}]
},
"requestIdentifier": new Date().getTime() + "", //remove通知需要
"triggerType": "timeInterval", //push timeInterval calendar location
"timeInterval": { //triggerType为timeInterval,才有效
"timeInterval": 5,
"repeats": false //如果设置重复,重复时长要大于60s
},
"calendar": { //triggerType为calendar,才有效
"dateComponents": { //什么时间时候之后显示通知
//"era": 0,
//"year": 2022,
//"month": 9,
//"day": 9,
//"hour": 14,
//"minute": 3,
"second": 3,
// "nanosecond": 0,
// "weekday": 0,
// "weekdayOrdinal": 0,
// "quarter": 0,
// "weekOfMonth": 0,
// "weekOfYear": 0,
// "yearForWeekOfYear": 0,
},
"repeats": false //是否重复
},
"location": { //triggerType为location,才有效
"latitude": 39.788857,
"longitude": 116.5559392,
"radius": 500,
"identifier": "identifier",
"notifyOnEntry": true,
"notifyOnExit": true,
"repeats": false //是否重复
}
}
KJNotification.addLocalNotification(dic, (res) => {
console.log("addLocalNotification:" + JSON.stringify(res));
});
},
removeAllDeliveredNotifications() {
KJNotification.removeAllDeliveredNotifications();
},
removeDeliveredNotificationsWithIdentifiers() {
KJNotification.removeDeliveredNotificationsWithIdentifiers(["requestIdentifier"]);
},
getDeliveredNotificationsWithCompletionHandler() {
KJNotification.getDeliveredNotificationsWithCompletionHandler((res) => {
console.log("getDeliveredNotificationsWithCompletionHandler:" + JSON.stringify(res));
});
},
removeAllPendingNotificationRequests() {
KJNotification.removeAllPendingNotificationRequests();
},
removePendingNotificationRequestsWithIdentifiers() {
KJNotification.removePendingNotificationRequestsWithIdentifiers(["requestIdentifier"]);
},
getPendingNotificationRequestsWithCompletionHandler() {
KJNotification.getPendingNotificationRequestsWithCompletionHandler((res) => {
console.log("getPendingNotificationRequestsWithCompletionHandler:" + JSON.stringify(res));
});
}
}
}
</script>
<style>
.content {
text-align: center;
}
.text {
color: red;
padding: 10px;
font-size: 18px;
}
</style>