I am trying to implement an alarm type app that sets a UILocalNotification from a UIDatePicker (only time, no date). I kind of have it working except for the fact that lets assume it is 5:00 PM when the user tries to set the alarm. If they try to set the alarm for 4:45 PM
(let us assume they are doing this for the following day) it wont set the UILocalNotification. I am sure that it is because of my code and specifically the “setHour” or “setMinute” or the way I have the my nsdates with the calendar. If anyone can tell me what I need to do to get it work, it would be appreciated.
the name of the UIDatePicker is
datePick
Thanks!
UILocalNotification *futureAlert;
futureAlert = [[UILocalNotification alloc] init];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
//[dateComps setDay:item.day];
//[dateComps setMonth:item.month];
//[dateComps setYear:item.year];
[dateComps setHour:11];
[dateComps setMinute:46];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
futureAlert.fireDate = [datePick date];
futureAlert.timeZone = [NSTimeZone defaultTimeZone];
futureAlert.alertBody= @"time to wake up";
[[UIApplication sharedApplication] scheduleLocalNotification:futureAlert];
[futureAlert release];
Try use this code lines:
where interval in your case will equal to 85500 secs. In 24 hours a 86400 secs, 15 min – 900 secs, then a 23 hours 45 min – 85500 secs (86400 – 900).
So, you can calc a interval seconds and use it