earliestBeginDate timezone

I'm trying to schedule a background task that will run on an iPhone and I'm looking into creating a task request using BGProcessingTaskRequest and scheduled it using BGTaskScheduler.shared.submit().

Per earliestBeginDate documentation, this property can be used to specify the earliest time a background task will be launched by OS. All clear here.

However, the question is: how is the value interpreted with respect to timezone ? Is the specified date in device timezone ? Is GMT ? Is something else ?

Written by VasileGreabanu in 779047021
how is the value interpreted with respect to timezone ?

It is not. It’s of type Date, and Date represents a fixed point in time. Under the covers it’s actually on offset, in seconds, from the reference date (the beginning of 2001).

If you want to specify specify a local time, create a DateComponents value and pass that into Calendar to get a Date.

There is one gotcha though: If the device changes time zone after when your schedule your task, there’s no easy way for you to adjust for that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Per earliestBeginDate documentation, this property can be used to specify the earliest time a background task will be launched by OS. All clear here.

One small note here. The API REALLY does mean "the earliest time". That is, you are telling the system "do not run this task BEFORE this time", NOT "please run the task around this time". On most device, "background task time" happens on a fairly consistent schedule (typically, "in the middle of the night while your device charging") and all manipulating "earliestBeginDate" can do is push your task further away from that point.

The second most common mistake I see developer make is scheduling tasks in a way that inadvertently guarantees that task will not run. For example, if your app is used every day and every day you set "earliestBeginDate" as "6am tomorrow" then, on most device, that task will never execute.

I'd also suggest reading through this post for a quick overview of other issues that commonly trip up developers.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

earliestBeginDate timezone
 
 
Q