/ Published in: Objective C
Show a notification immediately after application enter in background (but you can schedule it too)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"application: didFinishLaunchingWithOptions:"); // Override point for customization after application launch UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 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.alertBody = @"this is a notification!"; localNotif.alertAction = @"notification"; // action button title localNotif.soundName = UILocalNotificationDefaultSoundName; // keep some info for later use localNotif.userInfo = infoDict; [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; [localNotif release]; }
URL: http://iphonesdkdev.blogspot.com/2010/04/local-push-notification-sample-code-os.html