简体   繁体   English

目标 C:如何检查未读消息(要显示为徽章的数字)

[英]Objective C: How to check for unread messages (number to be displayed as badge)

I have a tableView storing a list of notifications (retrieved from server).我有一个 tableView 存储通知列表(从服务器检索)。 How can I check if the particular notification has been viewed by the user?如何检查用户是否查看了特定通知?

I was thinking of我在想

1) storing the notification ids in NSUserdefaults and 1) 将通知 ID 存储在 NSUserdefaults 和

2) check the retrieved notification list against the list in NSUserdefault at app launch, 2) 在应用启动时,对照 NSUserdefault 中的列表检查检索到的通知列表,

3) if the notification does not exist in NSUserdefault, then notification == unread and badgeValueCount++. 3)如果通知在NSUserdefault中不存在,则通知==未读和badgeValueCount++。

However this seems highly inefficient and not scalable.然而,这似乎非常低效且不可扩展。

Can anyone advise a more efficient way of checking for unread items (and setting the badge with the unread count).任何人都可以建议一种更有效的方法来检查未读项目(并使用未读计数设置徽章)。 Thanks!谢谢!

Why not simply storing your 'notifications' in some array?为什么不简单地将您的“通知”存储在某个数组中? You will be able to have the count of objects in the array, and also check wether an object is inside the array.您将能够获得数组中对象的计数,并检查 object 是否在数组内。

This depends a lot on your system.这在很大程度上取决于您的系统。 For example, if the user might have several clients fetching the notifications and you want synchronization between them, the information will have to be stored server-side as part of the user data.例如,如果用户可能有多个客户端获取通知并且您希望在它们之间进行同步,则必须将信息作为用户数据的一部分存储在服务器端。 If this is purely a client-side concern and the notifications are indexed by time, you can just store the last pull date and ask the server how many notifications are newer than that.如果这纯粹是客户端的问题,并且通知是按时间索引的,您可以只存储最后一次拉取日期并询问服务器有多少通知比那个更新。 Failing all of that, a list of notification IDs makes sense (though I would feel weird about putting it in the user defaults, just out of a sense of neatness and not wanting to bloat an app's defaults over time).如果所有这些都失败了,通知 ID 列表是有意义的(尽管我觉得将它放在用户默认值中会很奇怪,只是出于整洁的感觉,并且不想随着时间的推移使应用程序的默认值膨胀)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM