UILocalNotification Click Event

my code is:

- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet { NSLog(@"didReceiveEvent(),%@",packet.data ); SysNotification *sysNotification=[GlobalVariable parseSysNotificationWithString:packet.data]; UILocalNotification *alarm = [[UILocalNotification alloc] init]; if (alarm) { alarm.fireDate = [NSDate date]; alarm.timeZone = [NSTimeZone defaultTimeZone]; alarm.repeatInterval = 0; alarm.soundName = UILocalNotificationDefaultSoundName; alarm.alertBody = @"Test message..."; NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"]; alarm.userInfo = infoDic; [[UIApplication sharedApplication] presentLocalNotificationNow:alarm]; } } 

I want, when I press UILocalNotification in the status bar, I can go to some view controller. How to make? thanks

+3
source share
1 answer

There are two scenarios for processing local notifications,

1. The application starts due to a local notification click

 -(BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotif) { //load your controller } return YES; } 

2. The application is active , then add this code to AppDelegate

  -(void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { //load your controller } 
+5
source

All Articles