Return to Snippet

Revision: 41899
at February 24, 2011 12:07 by rabc

Initial Code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
 NSLog(@"application: didFinishLaunchingWithOptions:");
    // Override point for customization after application launch
 UILocalNotification *localNotif = [launchOptions
 if (localNotif) {
 // has notifications
 else {
  [[UIApplication sharedApplication] cancelAllLocalNotifications];
 [window makeKeyAndVisible];
 return YES;

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif {
   NSLog(@"application: didReceiveLocalNotification:");

- (void)applicationDidEnterBackground:(UIApplication *)application {

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    localNotif.fireDate = [NSDate date]; // show now, but you can set other date to schedule
    localNotif.alertBody = @"this is a notification!";
    localNotif.alertAction = @"notification"; // action button title
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    // keep some info for later use
  	NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"item-one",@"item", nil];
    localNotif.userInfo = infoDict;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

Initial URL

Initial Description
Show a notification immediately after application enter in background (but you can schedule it too)

Initial Title
Schedule app local notification

Initial Tags
background, iphone, ios

Initial Language
Objective C