gpt4 book ai didi

ios - Expo - 实现通知设置应用程序图标角标(Badge)编号

转载 作者:行者123 更新时间:2023-11-29 05:15:26 25 4
gpt4 key购买 nike

尽管多次尝试在我们的 Expo 应用程序中实现应用程序图标角标(Badge)编号,但仍无法设置应用程序图标角标(Badge)编号。有关设置通知应用程序图标角标(Badge)数量的文档也非常有限。我们尝试在有新的推送通知时将应用程序图标角标(Badge)编号设置为 1,然后在用户单击通知后将应用程序图标角标(Badge)编号重置为 0。

谁能指出这里出了什么问题吗?

以下是通知监听器的回调函数。

handleNotification = async (notification) => {
const { origin, data, notificationId } = notification
const notif = { id: notificationId, ...data }

// set notifications badge count
try {
const setAppBadgeCount = await Notifications.setBadgeNumberAsync(1)
console.log(`showing app badge number to 1 ${setAppBadgeCount}`)
} catch (err) {
console.log('did not manage to show notif app badge count!', err)
}
if (origin === 'selected') {
this.navigateToNotificationScreen(data)
try {
const resetAppBadgeCount = await Notifications.setBadgeNumberAsync(0)
console.log(`reset app badge count ${resetAppBadgeCount}`)
} catch (err) {
console.log('did not manage to reset notif app badge count!', err)
}
} else { // origin === 'received', show in-app
const { dispatch } = this.props
dispatch(setActiveNotifications([notif]))

setTimeout(() => {
dispatch(setInactiveNotifications([notif]))
}, 10000)
}
}

提前致谢!

最佳答案

啊,我被提醒我没有在这里留下我的解决方案。就我而言,Expo 前端代码编写得非常完美。我上面写的方式就像一个魅力。对我来说,问题是发送到 Expo 服务器的后端请求未正确写入。请参阅此链接 - https://docs.expo.io/versions/latest/guides/push-notifications/#sending-notifications-from-your-server

[
{
"to": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
"sound": "default",
"body": "Hello world!"
},
{
"to": "ExponentPushToken[yyyyyyyyyyyyyyyyyyyyyy]",
"badge": 1,
"body": "You've got mail"
},
{
"to": [
"ExponentPushToken[zzzzzzzzzzzzzzzzzzzzzz]",
"ExponentPushToken[aaaaaaaaaaaaaaaaaaaaaa]"
],
"body": "Breaking news!"
}
]

具体来说,我没有在发送到 Expo 服务器的通知的请求正文中添加参数 "badge": 1 。因此,应用程序图标角标(Badge)编号根本没有设置。

关于ios - Expo - 实现通知设置应用程序图标角标(Badge)编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59231671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com