UILocalNotification 100

Tomato SoupThere are a lot of cases where you will want to notify your user of some event of reminder without actually setting a formal alarm in their Alarm app. The standard solution most developers seem to take in these situations is to setup something like Urban Airship and fire off a push notification – this costly and shares the user’s data for no reason. Using
iOS’s UILocalNotification, you can pop a push-like notification without worrying about the hassle and potential cost of a push service and without sending any user data over the air. Checkout how easy it is to fire off a simple notification from this simple from my newly released Pomodoro timer Tomato Soup:

- (void)createNotificationForPomo:(TSPomodoro *)pomo
{
	UILocalNotification* notification = [[UILocalNotification alloc] init];
	notification.fireDate = pomo.fireDate;
	notification.alertBody = [NSString stringWithFormat:@"Nice work! Pomodoro: %@ is complete!", pomo.title];
	[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

// Now let's remove all notifications
- (void)removeNotifications
{
	[[UIApplication sharedApplication] cancelAllLocalNotifications];
}

Notifications like the one created above will still fire if the app is in the background, however, if you don’t want them to fire if the app is active, you will have to deactivate them on willResumeActive.I hope this helps you and that you reconsider how often you send user data over the air and use UILocalNotification as a simple alternative to push when appropriate.

Comments? Questions? Drop me a line on App.net, Google+, or Twitter. Also, pickup Code Journal.

Comments are closed.