【问题标题】:How does Alarmy App send continues local notification after App killed?App被杀后Alarmy App如何发送继续本地通知?
【发布时间】:2022-01-01 15:59:43
【问题描述】:

我想知道如何在 ios (Swift) 中触发连续的本地通知,我在 for 循环中运行本地通知代码,但是当我终止应用程序时,它不会执行完整的代码。

【问题讨论】:

  • 当您的应用处于终止状态时,您无法发送本地通知。
  • 那么Alarmy app是怎么做的呢?
  • 你确定他们正在发送本地推送通知
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: ios swift iphone ipad swift5


【解决方案1】:

尝试以下方法:

let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "World"
content.badge = 1
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let request = UNNotificationRequest(identifier: "", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

【讨论】:

  • 我希望每 2 秒通知一次本地通知
  • 注意触发参数:(timeInterval: 60, repeats: true)
  • 是的,但要求最短时间为 60 秒。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多