you can use NSNotificationCenter to pass data.
in MainViewController.m
in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifMainController:) name:@"notifMainController" object:nil];
-(void)notifMainController:(NSNotification *)notif
{
NSLog(@"%@",notif.object);
}
in AppDelegate
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
NSLog(@"Recieved Notification %@",notif); // Handle the notificaton when the app is running
if (app.applicationState == UIApplicationStateInactive )
{
NSLog(@"app not running");
// I need to pass the data to main view controller
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
MainViewController *obj = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
[self.navC pushViewController:obj animated:NO];
[[NSNotificationCenter defaultCenter] postNotificationName:@"notifMainController" object:@"your string"];
});
}
else if(app.applicationState == UIApplicationStateActive )
{
NSLog(@"app running");
// I need to pass the data to main view controller
[[NSNotificationCenter defaultCenter] postNotificationName:@"notifMainController" object:@"your string"];
}
}
you can pass string in [[NSNotificationCenter defaultCenter] postNotificationName:@"notifMainController" object:@"your string"];
like this in object.
Maybe this will help you.