UILocal Notification not fire on schedule date and time when i set past date notification

StackOverflow https://stackoverflow.com/questions/21406602

  •  03-10-2022
  •  | 
  •  

Question

I am working with UILocalNotification. My app will give user facility to set the reminder for any meeting and medicine in my application.

I am Able to schedule UINotification according to my Schedule date. And also When user will schedule past date notification my secound schedule notification is not fired. After secound others are firing perfect but secound is not firing.

Following is my flow for notification:

  1. I am creating 3 schedule for meeting one of its time is past of my current time say for e.g. 2014-01-28 18:00. And my current device time is 2014-01-28 19:00. Now i am creating another schedule its time is i.e. 2014-01-28 19:10. And another schedule date and time is i.e. 2014-01-28 19:20.

  2. With the above schedule date time reference my first notification which was of past date was fired after schedule create.

  3. When my current time of device come to 2014-01-28 19:10. I was especting notification. but it wount fire.

  4. And at 2014-01-28 19:20 my 3rd notification fires as regularly. this things happen for me every times when I add past date as a schedule.

Following is my schedule notification code which i used to schedule notification:

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = alertText;
localNotification.alertAction = alertAction;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertLaunchImage = launchImage;
localNotification.applicationIconBadgeNumber = 1;
localNotification.userInfo = userInfo;

 [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
 [[UIApplication sharedApplication]registerForRemoteNotificationTypes:
         UIRemoteNotificationTypeBadge |
         UIRemoteNotificationTypeAlert |
         UIRemoteNotificationTypeSound];

Also Following is my idReceiveLocalNotification: method to hendle notification:

if([UIApplication sharedApplication].applicationIconBadgeNumber == 0) {
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    }else{
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    }

Also when i get notification at that time i will call MkLocalNotificationScheduler class to display alert which code is as follows:

 UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Reminder"
                                                         message:[thisNotification alertBody]
                                                        delegate:self
                                               cancelButtonTitle:@"NO"
                                               otherButtonTitles:@"YES",nil] autorelease];
        alert.tag = 1;
        [alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

Please help me how to work on to get all Schedule notification weather it is past date or date yet to be come.

Was it helpful?

Solution

Do not create UILocalNotification for time that is past. The behavior that you are seeing is typical of UILocalNotification. It fires past event right away. So in your code check if the time has past and if it is then don't create a UILocalNotification. (also its non-sense to create a notification of past time)

Only create new UILocalNotification for times that are in future of your current time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top