UILocalNotifications Epiphany
Posted by Chris on Aug 18, 2010 in iOS Apps, iPhone | 0 comments
While reading iPhone Developer’s Cookbook, I had a strange epiphany. I was finishing up the chapter on Objective-C Boot Camp, and the idea hit me. I recently had a tough time implementing local push notifications into iSupplement (also iRx Tracker).
The way I got stuck following was by calling my refreshLocalNotifications method within my main table view. Essentially this allowed me update all notifications per the NSIndexPath number. The problem with this was that the entire table had to refreshed every time the user takes a supplement. Another draw back was that when you scroll the tableView, and a cell leaves the screen, the table would update. Now this cheap way of getting things done was by forcing my DatePickerView to send a notification to the app saying “hey! we updated when the user took their supplement” this in turn caused the table view to reload. Now this operation ended up being very taxing. So while reading a simple solution came to me. Why do I have to update every local notification when 1 thing is taken? I don’t! So I added my refresh and remove local notification methods to the DatePickerView. Now I just have to pass the “current” supplement/medication to my DatePickerView and voila we update a single notification just once. Now the only issue that came up was with our undo button. If a user hits undo, they are not taken to the DatePickerView, therefore the notification can’t be removed. The solution? Simple: create an instance of DatePickerView, send it the object that we are working with, and cancel the notification. Once this is done we can release our “undisplayed” DatePickerView. This essentially takes all of the “processing” code for updates and puts it into 1 location to allow us to do it all at once, stop refreshing the table so often, and in turn improve performance 100 fold. This solution should have been more obvious to me in the begin but after re-reading about the different relationships and abilities gained from inheritance I realized that everything I need to refresh my notifications could be sent to the other methods and thus don’t need to iterate through every supplement every time. If there is enough interest I can post my various methods for my local push notifications. Anyway, enjoy!
Related posts:


