0

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!

Zhen
  • 12,361
  • 38
  • 122
  • 199
  • are your 'notifications' ? `NSString` ? –  Jul 13 '11 at 18:05
  • @Vince, they are objects that are retrieved from server everytime a user loads the table content. – Zhen Jul 13 '11 at 22:43
  • once the user tap the cell put the object your array, you will be able to know which have been read and which not –  Jul 14 '11 at 09:44
  • if you are trying just to calculate the number of unread, this number is the total count of notifications minus the count of those you put in the array –  Jul 14 '11 at 10:28

2 Answers2

1

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.

1

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

Chuck
  • 234,037
  • 30
  • 302
  • 389
  • the data is stored on the server side. Every time the user loads a table, he/she will retrieve an array of Notification objects from the server. Yes it is purely a client-side concern, if I base purely on last pull time, it is not really indicative on whether the user actually view the notification (actually clicked on the cell). Basically, I just want to model after the mail app, how is it possible to track the total unread like the mail app? – Zhen Jul 13 '11 at 22:42