1 Reply
      Latest reply on Nov 17, 2019 6:52 AM by eskimo
      KlemensStrasser Level 2 Level 2 (35 points)

        Hey,

         

        I have a question to the following scenario: We have a `UNUserNotification` that is scheduled for a certain date. The content of this notification might be subject to change as we get closer to its delivery. We now want to have a way to wake up (not earlier then a certain interval), refetch content and if something change, update/reschedule the Notification. We thought of using the BackgroundTasks to do it.

         

        My question is:

        Which type of task is the right one to use here? Or shouldn't we use the BackgroundTasks framework for this at all?

        • Problem with `BGAppRefreshTask`: My understanding was that the `BGAppRefreshTask` is scheduled intelengently before the app ususually is woken up by the user. So using it for refreshing a something that won't be followed by an app launch seems wrong.
        • Problem with 'BGProcessingTask': We do not need any heavy processing for our task. But I guess the system will think that we will need to do heavy processing since it is a `BGProcessingTask` and schedule it only if the system has a downtime.


        Also, just to be clear once and for all: Can there be only one `BGAppRefreshTask` for the app at a time? It kinda makes sense, but it isn't stated anywhere explicitly.

        Thanks,
        Klemens


        • Re: Refresh notification content with background task
          eskimo Apple Staff Apple Staff (12,455 points)

          We have a UNUserNotification that is scheduled for a certain date. The content of this notification might be subject to change as we get closer to its delivery.

          My preferred way to do this is to offload the logic for ‘rendering’ the notification to a push provider.  At that point your app doesn’t need to resume in the background and update the notification; rather, the push provider just sends the right push notification at the right time.

          If you can’t do that, refreshing the notification on the client is going to be problematic.  BGAppRefreshTask is the right option for this but most developers who try to use this tech (which is equivalent to the old ‘background fetch’ mechanism) are disappointed with how infrequently it resumes their app.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"