0

Local Notifications fire if scheduled in the foreground. If the app is in the background, local notifications are not scheduled, but I want them to schedule and immediately fire. Posts on this topic discuss how apps in iOS 10+ are suspended quickly and therefore local notifications will not be scheduled, however, apple docs say

You schedule local notifications at a time when your app is running either in the foreground or background.

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html

Does this mean that in iOS 10+, there is no way for local notifications to schedule if the user has closed the app (ie: suspended)? How do "big" apps do it?

I've seen some people consider enabling 'Background Modes.' My app allows people to connect like on social media, and I want the connect 'requests' to prompt the immediate notification. Is this appropriate for enabling Background modes?

Lastly, what is the point of a notification if it cant be sent when the user has the app closed? It sounds like in iOS10+, apps that don't have background modes are either 'in the foreground' or 'suspended.' Therefore, a local notification would never even send unless "shouldAlwaysAlertWhileAppIsForeground" was enabled. Even then, what good is getting a notification only in the foreground.

Just as reference, here is how I schedule local notifications:

        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)
Ryan Pierce
  • 1,583
  • 16
  • 24
  • You haven't scheduled that notification for future delivery; Do you want it delivered "now"? If so, how are you calling this code? – Paulw11 Sep 27 '17 at 01:19
  • Yes, "now" or instant notification is what I want. The code is called when a listener fires that is attached to my database. The point is I want the notification to fire the exact moment the request is added to the notificationCenter in the background. But everyone is saying that's impossible since ios10+ apps are immediately suspended and thus can't create any new notifications. – Ryan Pierce Sep 27 '17 at 02:12
  • That is why I asked how you are expecting this code to be run - What is causing your app to execute in the background? Where, in your app, is the code you have shown? – Paulw11 Sep 27 '17 at 02:13
  • Database listener, so the notification is made in an anonymous function. – Ryan Pierce Sep 27 '17 at 02:15
  • But your database listener won't fire in the background unless it is triggered by something like a push notification; there are only limited background execution modes on iOS; this isn't new with iOS 10. – Paulw11 Sep 27 '17 at 02:24
  • So are Push Notifications and enabling Background Modes the only option for notifying the user in this manner? Is a social media type app appropriate for enabling Background Modes? – Ryan Pierce Sep 27 '17 at 02:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/155369/discussion-between-paulw11-and-vlpplpryguy). – Paulw11 Sep 27 '17 at 02:31

0 Answers0