2

我尝试在 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];
}

我做错了什么?

4

1 回答 1

0

通知触发时,您的应用不得在前台运行。

如果你想在前台播放声音,你可以使用UIAlertView和'AvAudioPlayer'的组合。

您可以在

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification的委托方法AppDelegate.m

欢迎进一步询问。

于 2013-12-26T13:53:55.813 回答