【问题标题】:Play Alarm Sound when app is not running IOS当应用程序未运行 IOS 时播放警报声音
【发布时间】:2015-09-17 09:48:39
【问题描述】:

我一直在开发 IOS 警报应用程序。我将在应用程序中创建警报的位置。所以我需要闹钟在 IOS 中作为“时钟”应用程序工作。

当闹钟时间到达并且应用程序未运行时。警报声将播放,用户可以通过单击取消或打盹来停止它..

【问题讨论】:

  • 使用本地通知并通过点击通知启动适当的控制器,以便用户可以打盹或取消警报。
  • 第一件事我将如何安排闹钟?
  • 您不能这样安排闹钟。您将安排一个 UILocalNotification。
  • 详细教程here。您会在 SO 上找到许多与此问题相关的帖子。

标签: ios audio notifications alarm


【解决方案1】:

对于您需要使用UILocalNotification的闹钟您可以使用应用程序设置闹钟时间表,如下所示:

- (void)scheduleLocalNotificationWithDate:(NSDate *)fireDate {
  UILocalNotification *localNotification = [[UILocalNotification alloc] init];

  [localNotification setFireDate:fireDate];
  [localNotification setAlertBody:@"Time to wake up!"];
  [localNotification setSoundName:@"Thunder Song.m4r"];

  [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

这里有两个Github 链接,例如代码或警报,但 UILocalNotification 没有任何设置贪睡的方法:

https://github.com/retsohuang/AlarmClock

https://github.com/bauerjon/Alarm-Clock-iOS

【讨论】:

  • 我尝试使用上面的代码。但它没有显示通知。现在是下午 4:02 我通过的日期是:- 2015-09-17 16:05:00 +0000 但它没有显示通知。
  • 您需要对这个新的演示进行更多研究,代码是否正确检查设置时间github.com/eliotfowler/awake
  • 即使设备处于静音模式,它会播放声音吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-16
  • 2016-09-27
  • 2013-04-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多