UILocalNotification从选取器开始

我试图实现一个报警types的应用程序,从UIDatePicker设置一个UILocalNotification(只有时间,没有date)。 我有一种工作,除了假设用户试图设置闹钟的时间5:00 PM 。 如果他们尝试设置下午4:45的警报(让我们假设他们正在这样做的翌日)它不会设置UILocalNotification。 我相信这是因为我的代码,特别是“setHour”或“setMinute”,或者我有我的nsdates与日历的方式。 如果有人能告诉我,我需要做些什么才能使它工作,这将不胜感激。

UIDatePicker的名字是

datePick 

谢谢!

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

尝试使用此代码行:

 double interval = [datePick.date timeIntervalSinceNow]; // time interval if (interval < 0) // if time is earling at this time interval += 86400; // for set this time at next day futureAlert.fireDate = [[NSDate date] dateByAddingTimeInterval: interval]; futureAlert.timeZone = [NSTimeZone systemTimeZone]; 

在你的情况下间隔将等于85500秒。 24小时内86400秒,15分-900秒,23小时45分–85500秒(86400 – 900)。

所以,你可以计算间隔秒数,并使用它