开发者

Best way to show updated badge count on tab bar item on the iPhone

The iPhone app I'm working on primarily gets its data from a web app through an API. For the sake of the details, let's just say I'm working on an activity feed.

My question is, what's the best way to get the count of the new items that need to be viewed, so I can stick a badge on the appropriate tab bar item?

Since that could be confusing/too general, here's what I'm thinking...

I would undoubtedly ha开发者_开发问答ve to store some sort of timestamp or something locally on the phone (should I use SQLite for that?). So let's say each time a person taps on the tab item that has the feed list, I record that timestamp using whatever method... SQLite, file, etc. Then, I could have an API call that essentially gets the new activity items that are newer than that stored timestamp, and if the difference is larger than zero, show a badge.

However, I'm stuck on when this should happen, and the overall process involved. When should I make the initial call? If I do it in AppDelegate, it will never get called again, right? (because AppDelegate never reloads itself?) I could do it when the person clicks on the tab, but that defeats the purpose because I'd like to give them a reason to click on the tab (I don't click on the voicemail tab to see if I have voicemail, only if there's a badge telling me I do). And then there's the issue of updating the badge while the user is in the app - background task? (I'm okay ignoring this part for now)

Hopefully you can see what I'm trying to do... thoughts, ideas, and/or suggestions are much appreciated.

Thanks!


There are many different ways to do this (if I understand what you are trying to do). As this is a rather general question I can only give general answers.

Firstly as this is a tab bar App I would probably create an NSTimer in the App delegate to call the network connection every 60 seconds perhaps. The call that you are interested in is

scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
This allows you to specify a method that is called every x seconds to run.

You could also do this in a thread and sleep the thread for 60 seconds after the connection has been complete. If you are starting of iPhone development I would probably stick with the NSTimer for the meantime.

As far as storage is concerned its kind of dependant of how much and the sorting that is needed if you use sqlite or not. It might even be possible just to use an NSDictionary stored in an NSMutableArray that stores the information with a timestamp.

The problem with the timestamp thing is, after a certain time period is it considered read? If not a BOOL might be better, once the user reads turn the bool to false and make a call to the App delegate to reload the badge number based on the amount of entries with bool is true.

Once again an abstract view of the problem. Let me know if you need more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜