Почему метод полученного локального уведомления не работает?

У меня есть приложение, в котором я установил локальное уведомление в своем файле class.m, которое показано ниже: -

-(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];

}

и я использовал код в своем файле appdelegate: -

- (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);

}

Теперь ошибка заключается в том, что при генерации уведомления вызов didReceiveLocalNotification не выполняется. Как исправить эту ошибку?

Заранее спасибо...


person ios    schedule 07.12.2011    source источник
comment
этот метод будет работать, когда приложение находится на переднем плане   -  person Leena    schedule 07.12.2011
comment
@iPhone Developer, как мне улучшить это?   -  person ios    schedule 07.12.2011
comment
вы говорите, что происходит уведомление, но этот метод не вызывается, вы не можете вызывать какой-либо метод, когда ваше приложение находится в фоновом режиме.   -  person Leena    schedule 07.12.2011
comment
Разработчик @iPhone знаете ли вы какой-либо способ вызвать метод при выпуске уведомления?   -  person ios    schedule 07.12.2011
comment
он будет автоматически вызываться при появлении вашего уведомления, если и только если приложение находится на переднем плане.   -  person Leena    schedule 07.12.2011
comment
@iPhoneDeveloper, проверьте мой новый вопрос stackoverflow.com/questions/8411121/   -  person ios    schedule 07.12.2011
comment
давайте продолжим это обсуждение в чате   -  person ios    schedule 07.12.2011


Ответы (1)


  • (void) приложение: (UIApplication *) приложение didReceiveLocalNotification: (UILocalNotification *) уведомление; функция будет вызываться, когда мы нажимаем кнопку просмотра локального уведомления, а не кнопку закрытия.
person ios    schedule 22.02.2012