0

I have an application in which i have set a local notification in my class.m file which is show below:-

-(IBAction)save{
NSString *str1=[NSString stringWithFormat:@"%@",txt_date.text];
NSString *str2=[NSString stringWithFormat:@" %@",txt_time.text];
str1=[str1 stringByAppendingFormat:str2];
selected_label.text= str1;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSDate *today=[NSDate date]; 
NSDateFormatter* formatter_current = [[[NSDateFormatter alloc] init] autorelease];
formatter_current.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
//Set the required date format 
[formatter_current setDateFormat:@"yyyy-MM-dd hh:mm a"]; 

NSLog(@"current date is =%@",str1); 
today=[formatter_current dateFromString:str1];
NSLog(@"current date:-%@",today); 
UILocalNotification* ln = [[UILocalNotification alloc] init];
//ln.alertBody = @"Wake Up Sid";
//ln.applicationIconBadgeNumber = 1;
ln.fireDate = today; //[NSDate dateWithTimeIntervalSinceNow:15];
ln.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSLog(@"alarm will activate on%@",today);
NSDateFormatter* formatter_alarm = [[[NSDateFormatter alloc] init] autorelease];
NSLocale *uslocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[formatter_alarm setLocale:uslocale];
[uslocale release]; 
formatter_alarm.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[formatter_alarm setDateFormat:@"hh:mm a"]; 
NSString *str=[formatter_alarm stringFromDate:today];
NSLog(@"%@",str);
//ln.alertBody = [NSString stringWithFormat:@"Your first appointment at %@",str];
//ln.soundName = UILocalNotificationDefaultSoundName;
ln.repeatInterval=NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:ln];
[ln release];

}

and i used code in my appdelegate file is that:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// Override point for customization after application launch.


self.viewController=[[demo_social_updatesViewController alloc]initWithNibName:@"demo_social_updatesViewController" bundle:nil];
nav_controller=[[UINavigationController alloc] initWithRootViewController:self.viewController];
// Add the view controller's view to the window and display.
[self.window addSubview:nav_controller.view];
[self.window makeKeyAndVisible];
appDelegate_acess_token=[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"];
  application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
    NSLog(@"Recieved Notification %@",localNotif);
}
return YES;}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

     NSLog(@"Recieved Notification %@",notification);

}

Now error is that when notification is generate then didReceiveLocalNotification not call. How i fix this error?

Thanks in advances...

ios
  • 552
  • 5
  • 22
  • this method will work when application is in foreground – Leena Dec 07 '11 at 05:07
  • @iPhone Developer how i improve for that? – ios Dec 07 '11 at 05:30
  • you are saying that notification occurs but this method is not called, you cannot call any method when your app is in background. – Leena Dec 07 '11 at 05:39
  • @iPhone Developer have u know any way to call method when notification released ? – ios Dec 07 '11 at 05:48
  • it will automatically gets called when your notification occurs if and only if application is in foreground. – Leena Dec 07 '11 at 06:06
  • @iPhoneDeveloper check my new question http://stackoverflow.com/questions/8411121/how-implement-scheduling-event-with-post-a-message-on-fb – ios Dec 07 '11 at 06:11
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5644/discussion-between-user1033177-and-iphone-developer) – ios Dec 07 '11 at 06:18

1 Answers1

2
  • (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification; function will call when we tap on view button of local notification not on close button.
ios
  • 552
  • 5
  • 22