如果在前台安排了本地通知,则会触发。如果应用程序在后台,则不会安排本地通知,但我希望他们安排并立即触发。有关此主题的帖子讨论了iOS 10+中的应用如何快速暂停,因此不会安排本地通知,但是,苹果文档说
您可以在应用程序在前台或后台运行时安排本地通知。
这是否意味着在iOS 10+中,如果用户已关闭应用程序(即:已暂停),则无法安排本地通知安排? “大”应用程序如何做到这一点?
我见过有人考虑启用“背景模式”。我的应用程序允许人们像在社交媒体上一样连接,我希望连接“请求”提示立即通知。这适合启用后台模式吗?
最后,如果在用户关闭应用时无法发送通知,那么该通知的重点是什么?听起来像在iOS10 +中,没有后台模式的应用程序要么“在前台”,要么“暂停”。因此,除非启用“shouldAlwaysAlertWhileAppIsForeground”,否则本地通知永远不会发送。即使这样,只在前台获得通知才有好处。
作为参考,以下是我如何安排本地通知:
let center = UNUserNotificationCenter.current()
center.removeDeliveredNotifications(withIdentifiers: idsToBeCancelled)
let content = UNMutableNotificationContent()
content.title = title
content.body = text
content.categoryIdentifier = category
content.userInfo = map
content.sound = UNNotificationSound.default()
content.setValue("YES", forKeyPath: "shouldAlwaysAlertWhileAppIsForeground")
let request = UNNotificationRequest(identifier: "testing", content: content, trigger: nil)
center.add(request)