推送通知徽章自动递增

发布于 2024-08-16 09:58:43 字数 287 浏览 4 评论 0原文

我一直在为我的应用程序实现推送服务,并且我一直在考虑应用程序的徽章。我的应用程序是一个邮件应用程序(有点),我想通过推送通知用户添加到收件箱的新消息,我想要徽章 = 收件箱中的新消息数。

我想在服务器端(提供商)检查新消息并将数字作为徽章发送。

问题是: 有没有一种方法可以自动增加应用程序的徽章,而无需在服务器端计算徽章值,然后将其作为推送有效负载的一部分发送到 APSN?

也许有一种方法可以在 JSON 徽章字段中发送一些变量,例如“++”或类似的内容。 有什么技巧吗?或者我需要使用服务器端的计数系统吗?

I've been implementing the push service to my application, and I've been thinking about the application's badge. My app is a mail app (sorta) and I want to notify the user via push for new messages added to the inbox, I want the badge = number of new messages in the inbox.

I thought of doing it server sided (provider) checking for new messages and sending the number as the badge.

The question is:
Is there a way to auto-increment the application's badge, without having to calculate the badge value server sided and afterwards sending it as a part of the push payload to the APSN?

Maybe there's a way to send in JSON badge field some variable like "++" or something like that.
Any hack for that? Or do I need to go with the counting system server-sided??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

雾里花 2024-08-23 09:58:43

不,您必须在服务器端跟踪这一点。如果您不包含任何徽章值,它将被完全删除。

当然,这只适用于用户收到通知并且应用程序未运行/他们选择不启动它的情况。如果用户启动应用程序或已经运行它,您可以执行任何您想要的增量操作。

2014 年 3 月更新:查看评论以了解可能的更新。我已经好几年没有做过推送了,所以无法亲自验证这一点。

Nope, you'll have to track this on the server side. If you don't include any value for badge, it will get removed completely.

Of course though this is only if the user receives the notification and the app isn't running/they choose not to launch it. If the user launches the app or already had it running you can do whatever you want in regards to incrementing.

UPDATE March 2014: See comments for a possible update. I haven't done pushes in several years so haven't been able to verify this myself.

↙温凉少女 2024-08-23 09:58:43

这是可能的,但需要权衡。

您始终可以将未读总数作为附加 JSON 值作为推送有效负载的一部分发送(推送会忽略它未明确理解的键)。用户打开应用程序后,读取值并通过 UIApplication 的 applicationIconBadgeNumber 属性自行以编程方式调整徽章。

这样做的问题是,即使用户没有打开应用程序(即,当他们收到通知并且用户点击“取消”而不是“查看”时),推送也会调整徽章值。在这些情况下,您的徽章不会改变,但一旦他们运行应用程序(如果他们点击“查看”),您的应用程序就可以将其设置正确。

It's sort of possible but there's a trade-off.

You can always send up the unread total as an add-on JSON value as part of the push payload (push ignores keys it doesn't explicitly understand). Once the user opens the app, read the value and adjust the badge programmatically yourself via UIApplication's applicationIconBadgeNumber property.

The problem with doing it that way is that push adjusts the badge value even if the user doesn't open the app (i.e. when they get the notice and the user hits 'Cancel' instead of 'View'). In those cases your badge won't change, but as soon as they run the app (if they hit 'View') then your app can set it right.

森林迷了鹿 2024-08-23 09:58:43

现在可以让客户端使用 UNNotificationServiceExtension 自动增加徽章。

扩展程序能够在 iOS 显示通知负载之前修改通知负载。总之,将徽章计数器存储在 UserDefaults 中,并根据需要修改通知的徽章计数。您需要添加应用程序组功能来共享用户默认值。

以下是详细的分步指南:https:// prodocs.cometchat.com/docs/ios-increment-app-icon-badge-count

It is now possible to have the client auto-increment the badge using a UNNotificationServiceExtension.

Extensions have the ability to modify notification payloads before iOS displays them. In summary, store a badge counter in UserDefaults and modify the notification's badge count as needed. You'll need to add the App Groups capability to share User Defaults.

Here's a detailed step-by-step guide: https://prodocs.cometchat.com/docs/ios-increment-app-icon-badge-count

轻许诺言 2024-08-23 09:58:43

您可以尝试 App42 后端服务,它提供在服务器端维护的推送徽章计数的自动增量。有关更多详细信息,您可以点击 博客的链接。以下是博文内容:

以下是通过 App42 推送通知中的自动增量徽章计数可以实现的几个用例。

要使推送徽章自动递增 1,您需要发送推送消息,如下所示。

PushNotificationService pushNotificationService = App42API.BuildPushNotificationService (); // Initializing PushNotification Service.
string userName = "UserName";
string message= "{'badge':'increment'}";
pushNotificationService.SendPushMessageToUser(userName,message, new UnityCallBack())

注意:所解释的示例适用于 Unity/C#,但相同的过程也可以应用于其他应用。

如果您想要规定徽章的任意数量或者想要将徽章计数减少到零,您可以使用此方法在用户单击通知时更新计数。在这种情况下,您必须调用 updatePushBadgeforDevice 或 updatePushBadgeforUser。

PushNotificationService pushNotificationService = App42API.BuildPushNotificationService (); // Initializing PushNotification Service.
string userName = "UserName";
string deviceToken = "DeviceToken";
int badges = 10; // For clear count make it 0 
pushNotificationService.UpdatePushBadgeforDevice(userName, deviceToken, badges,  new UnityCallBack());

PushNotificationService pushNotificationService = App42API.BuildPushNotificationService (); // Initializing PushNotification Service.
string userName = "UserName";
int badges = 10; // For clear count make it 0
pushNotificationService.UpdatePushBadgeforUser(userName, badges,  new UnityCallBack());

updatePushBadgeforDevice – 此方法用于更新用户注册的特定设备的推送徽章计数。

updatePushBadgeforUser – 此方法用于更新用户购买的所有设备的推送徽章计数。在本例中,我们假设用户在其名下注册了多个设备。

You can try out App42 backend services which provide auto increment of push badge count which is maintained on the server side. For more details you can follow the link of blog. Here is the blogpost conent:

Here are the few use cases that can be achieved through auto incremental badge count in App42 Push Notification.

For auto increment of push badge by 1, you need to send push message as shown below.

PushNotificationService pushNotificationService = App42API.BuildPushNotificationService (); // Initializing PushNotification Service.
string userName = "UserName";
string message= "{'badge':'increment'}";
pushNotificationService.SendPushMessageToUser(userName,message, new UnityCallBack())

N.B: The sample explained is for Unity/C# but the same process can be applied on others too.

If you want to stipulate any number for the badge or want to reduce the badge count to zero, you can use this method to update the count as the notification gets clicked by the user. You have to call updatePushBadgeforDevice or updatePushBadgeforUser in this case.

PushNotificationService pushNotificationService = App42API.BuildPushNotificationService (); // Initializing PushNotification Service.
string userName = "UserName";
string deviceToken = "DeviceToken";
int badges = 10; // For clear count make it 0 
pushNotificationService.UpdatePushBadgeforDevice(userName, deviceToken, badges,  new UnityCallBack());

PushNotificationService pushNotificationService = App42API.BuildPushNotificationService (); // Initializing PushNotification Service.
string userName = "UserName";
int badges = 10; // For clear count make it 0
pushNotificationService.UpdatePushBadgeforUser(userName, badges,  new UnityCallBack());

updatePushBadgeforDevice – This method is used to update push badge count of a particular device registered by the user .

updatePushBadgeforUser – This method is used to update push badge count of all the devices that a user procures. In this case, we are assuming that the user has multiple devices registered under his name.

南冥有猫 2024-08-23 09:58:43

发送 +1 获取徽章计数,这将使徽章计数自动增加 1。

Send +1 for badge count, which will auto-increment the badge count by 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文