Background Task Scheduler

Hello,

An application I am working on would like to schedule push notifications for a medication reminder app. I am trying to use BGTaskScheduler to wake up periodically and submit the notifications based on the user's medication schedule.

I set up the task registration in my AppDelegate's didFinishLaunchingWithOptions method:

        BGTaskScheduler.shared.register(
          forTaskWithIdentifier: backgroundTaskIdentifier,
          using: nil) { task in
            self.scheduleNotifications()
            task.setTaskCompleted(success: true)
            self.scheduleAppRefresh()
        }

        scheduleAppRefresh()

I then schedule the task using:

    func scheduleAppRefresh() {
        let request = BGAppRefreshTaskRequest(identifier: backgroundTaskIdentifier)
        request.earliestBeginDate = Date(timeIntervalSinceNow: 60 * 1)

        do {
            try BGTaskScheduler.shared.submit(request)
        } catch {
        }
    }

In my testing, I can see the background task getting called once, but if I do not launch the application during the day. The background task does not get called the next day.

Is there something else I need to add to get repeated calls from the BGTaskScheduler?

Thank You, JR

Background Task Scheduler
 
 
Q