ios - 当应用程序未运行 IOS 时播放警报声音

标签 ios audio notifications alarm

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

当闹钟时间到达且应用程序未运行时。将播放闹钟声音,用户可以通过单击“取消”或“暂停”来停止它。

最佳答案

对于需要使用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

关于ios - 当应用程序未运行 IOS 时播放警报声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32627322/

相关文章:

ios - 当我测试它时,NSCache 在内存压力下不会删除项目,但是文档说它确实如此

ios - 为什么selectionStyle没有效果?

javascript - 音频无法在Howler.js中播放

notifications - Flutter:如何仅当我们使用 local_notification 单击通知时才执行操作?

在某些情况下,带有推送通知和后台进程的 Android 应用程序会被终止

ios - 错误处理、持久容器、通知 IOS

ios - 如何使用 UISearchBar 搜索文本和图片

ios - inputaccessoryview 未显示( Storyboard)

html - iOS HTML5 音频控件未显示

android - 将通知声音设置为默认声音