我尝试在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];
}
我做错了什么?
答案 0 :(得分:0)
当通知触发时,您的应用不得在前台运行。
如果您想在前台播放声音,可以使用UIAlertView
和'AvAudioPlayer'的组合。
您可以在
中设置此代码 -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
委托方法AppDelegate.m
。
随意进一步询问。