【问题标题】:Alarm Clock for iOSiOS 闹钟
【发布时间】: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


【解决方案1】:

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

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

您可以在

中设置此代码

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

欢迎进一步提问。

【讨论】:

    猜你喜欢
    • 2011-08-21
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2012-07-17
    • 2012-07-21
    相关资源
    最近更新 更多