OGeek|极客世界-中国程序员成长平台

标题: ios - 当应用程序未运行 IOS 时播放警报声音 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:17
标题: ios - 当应用程序未运行 IOS 时播放警报声音

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

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



Best Answer-推荐答案


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

- (void)scheduleLocalNotificationWithDateNSDate *)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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4