提交 d820be9a 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: 增加 push 示例

上级 b47f2532
...@@ -1075,6 +1075,15 @@ ...@@ -1075,6 +1075,15 @@
} }
}, },
// #endif // #endif
// #ifndef WEB
{
"path": "pages/API/push/push",
"group": "1,6,7",
"style": {
"navigationBarTitleText": "push | 推送"
}
},
// #endif
{ {
"path": "pages/tabBar/CSS", "path": "pages/tabBar/CSS",
"style": { "style": {
...@@ -2133,7 +2142,10 @@ ...@@ -2133,7 +2142,10 @@
"id": "api.device.installApk", "id": "api.device.installApk",
"name": "installApk" "name": "installApk"
}, },
null, {
"id": "api.device.push",
"name": "push"
},
{ {
"id": "api.device.getBatteryInfo", "id": "api.device.getBatteryInfo",
"name": "getBatteryInfo" "name": "getBatteryInfo"
......
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #ifdef APP-ANDROID -->
<button class="normal-button" type="default" @click="handleCreateChannel">
创建通知渠道
</button>
<button class="normal-button" type="default" @click="handleGetAllChannels">
获取所有通知渠道信息
</button>
<!-- #endif -->
<button class="normal-button" type="default" @click="handleCreateLocalNotification">
创建本地通知消息
</button>
<button class="normal-button" type="default" @click="handleSetBadge">
设置角标
</button>
<button class="normal-button" type="default" @click="handleCleanBadge">
清空角标
</button>
<button class="normal-button" type="default" @click="handleGetClientId">
获取cid
</button>
</scroll-view>
<!-- #endif -->
</template>
<script setup>
const handleCreateChannel = () => {
// #ifdef APP-ANDROID
const manager = uni.getChannelManager()
manager.setPushChannel({
channelId: "msg-pass",
channelDesc: "留言审核通过",
} as SetPushChannelOptions)
// #endif
}
const handleGetAllChannels = () => {
// #ifdef APP-ANDROID
const manager = uni.getChannelManager()
console.log("channels : " + manager.getAllChannels());
// #endif
}
const handleCreateLocalNotification = () => {
// #ifdef APP-ANDROID
if (uni.getAppAuthorizeSetting().notificationAuthorized == "authorized") {
// #endif
handleCreateChannel()
uni.createPushMessage({
title: "halo",
content: "world",
// cover:true,
channelId: "msg-pass",
when: Date.now() + 10000,
icon: "/static/uni.png",
// delay:5,
payload: {
pkey: "pvalue1"
},
category: "IM",
success(res) {
console.log("res: " + res);
},
fail(e) {
console.log("fail :" + e);
}
})
// #ifdef APP-ANDROID
} else {
uni.showToast({
title: "请在设置中开启通知权限",
icon: "error"
})
}
// #endif
}
const handleGetClientId = () => {
uni.getPushClientId({
complete(e : any) {
console.log(e);
}
})
}
const handleSetBadge = () => {
uni.setAppBadgeNumber(5)
}
const handleCleanBadge = () => {
uni.setAppBadgeNumber(0)
}
</script>
<style>
.normal-button {
width: 100%;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册