简体   繁体   中英

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). 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

2) check the retrieved notification list against the list in NSUserdefault at app launch,

3) if the notification does not exist in NSUserdefault, then notification == unread and 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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