0

Hello i am facing a weird kind problem. Actually i want to schedule a daily notification (only once a day) at 8:00 AM. Below is my code for scheduling daily notification.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];
NSDate *date = [[NSDate alloc] init];
date = [formatter dateFromString:@"08:00"];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.timeZone=[NSTimeZone defaultTimeZone];
localNotification.alertBody = @"You just received a local notification";
localNotification.alertAction = @"View Details";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[formatter release];
[date release];

My problem is, I receive 2 local notifications. One at 8:00 AM and other at 10:00 AM. Why i am getting notification at 10:00 AM. I am scheduling it at 8:00 AM only. I know UILocalNotification library have some other weird kind of problems/bugs on most of apple devices. I just want to confirm whether there is some mistake in my code or it is a weird behaviour of UILocalNotification Library. I dont know why Apple is not working on resolving the issues being reported by many developers about UILocalNotification.

Note: I am using Xcode 4.6 and iOS 6.1

Shahid Iqbal
  • 2,059
  • 2
  • 21
  • 29
  • :Add am/pm in your date. That is your problem. [formatter setDateFormat:@"HH:mm a"]; set your date format like this – TamilKing Nov 04 '13 at 07:30
  • Try to `[[UIApplication sharedApplication] cancelAllLocalNotifications];` before you schedule a local notification. And, your code is not good from the memory management point of view. Change your `NSDate *date = [[NSDate alloc] init]; date = [formatter dateFromString:@"08:00"];` lines to `NSDate *date =[formatter dateFromString:@"08:00"];`, and remove the `[date release];` line, and also don't forget to `release` you local notification object after scheduling it. Hope this helps! – Fahri Azimov Nov 04 '13 at 07:33

1 Answers1

1

This would be the BEST link to get your answer.

iMash
  • 1,178
  • 1
  • 12
  • 33