【发布时间】:2013-08-23 22:10:08
【问题描述】:
我尝试在 Xcode 4.6.3 下重写以下教程 - http://vimeo.com/29824336
但我的问题是在 24:00 左右我的代码没有发出警报:
-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = fireDate;
notification.alertBody = @"Time to wake up!";
notification.soundName = @"SNSD-Oh.caf";
NSLog(@"Ring Ring Ring!");
[[UIApplication sharedApplication] scheduleLocalNotification: notification];
}
- (IBAction) alarmSetButtonTapped:(id)sender
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;
NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date];
NSLog(@"Alarm Set Button tapped: %@", dateTimeString);
[self scheduleLocalNotificationWithDate: dateTimePicker.date];
}
我做错了什么?
【问题讨论】:
-
您的应用在 24:00 是否在前台?如果在系统发送通知时应用程序处于最前面且可见,则不会显示警报,不会标记图标,也不会播放声音。
-
你确定你的日期有正确的时区部分吗?
-
@claireware 谢谢。这样可行。现在我从上面收到一个小弹出窗口。但是我收到了两次?并且没有声音播放。
标签: ios nsdate uilocalnotification uidatepicker