【发布时间】:2012-08-15 10:27:14
【问题描述】:
我正在尝试实现一个警报类型应用程序,该应用程序从 UIDatePicker 设置 UILocalNotification(只有时间,没有日期)。我有点让它工作,除了让我们假设它是 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];
【问题讨论】:
标签: objective-c ios xcode