2013-11-19 6 views
1

Я реализую локальное уведомление в своем приложении. На экране я разместил два текстовых поля со временем. Например, первое текстовое поле, имеющее 2,44 часа и второе текстовое поле, имеющее 2,45 вечера. Местное уведомление первого текстового поля не запускается в 2.44 часа. но уведомление о выпуске 2:45 вечера выполняется правильно. И, 2,44 часа показ уведомлений с 14:45.Два местных уведомления не сжигание

// viewcontroller.m file 

Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls != nil) 
    { 
     [[UIApplication sharedApplication] cancelAllLocalNotifications]; 

     UILocalNotification *notif = [[cls alloc] init]; 
     notif.fireDate = [datePicker date]; 
     notif.timeZone = [NSTimeZone defaultTimeZone]; 
     { 
      if ([MorningTimelbl.text length]>0) 
      { 
       notif.fireDate = [datePicker date]; 
       notif.timeZone = [NSTimeZone defaultTimeZone]; 
       notif.alertBody = @"It's time to take your eye drops"; 
       notif.alertAction = @"Morning Notification"; 
       notif.soundName = UILocalNotificationDefaultSoundName; 


       notif.applicationIconBadgeNumber = 1; 
       notif.repeatInterval = NSDayCalendarUnit; 
       NSDictionary *mornDict = [NSDictionary dictionaryWithObject:MorningTimelbl.text 
                    forKey:kRemindMeNotificationDataKey]; 
       notif.userInfo = mornDict; 
       [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
      } 
      if ([LunchTimelbl.text length]>0) 
      { 
       notif.fireDate = [datePicker date]; 
       notif.timeZone = [NSTimeZone defaultTimeZone]; 
       notif.alertBody = @"It's time to take your eye drops"; 
       notif.alertAction = @"Lunch Notification"; 
       notif.soundName = UILocalNotificationDefaultSoundName; 
       notif.applicationIconBadgeNumber = 1; 
       notif.repeatInterval = NSDayCalendarUnit; 
       NSDictionary *lunchDict = [NSDictionary dictionaryWithObject:LunchTimelbl.text 
                    forKey:kRemindMeNotificationDataKey]; 
       notif.userInfo = lunchDict;     
       [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
      } 
} 

//appdelegate.m 

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{ 
    UIApplicationState state = [application applicationState]; 
    if (state == UIApplicationStateActive) 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder" 
                 message:notification.alertBody 
                 delegate:self cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 

    } 
    // Set icon badge number to zero 
    application.applicationIconBadgeNumber = 0; 
} 

, где я сделал ошибку? Спасибо заранее.

+3

вы устанавливаете оба уведомления notif.fireDate такой же проблема. –

+0

Спасибо за быстрый ответ. подождите, я проверю сейчас – Ramdhas

+0

Спасибо за быстрый ответ. Я., его работа. спасибо много @DhavalBhadania – Ramdhas

ответ

1

Изменение в соответствии с вы хотите:

ДЛЯ MorningTimelbl.text

  • notif.fireDate = Morningtime-date; // установить дату, как вы хотите Morningtime Дата размещения

для следующего (второго уведомления) LunchTimelbl .text

  • notif.fireDate = LunchTime-date; // дата установки как вы хотите на LunchTime-date
+0

Но, fireDate - это тип NSDate. Таким образом, нужно преобразовать значение morningTimelbl.text в тип NSDate. – Ramdhas

+0

@Ramdy да там нужно установить разные nsdate. –

+0

Не упустите Upvote для моего вопроса. Из-за меньшей репутации я не могу дать вам ответ. – Ramdhas

Смежные вопросы