I am changing my deprecated function setMinimumBackgroundFetchInterval() to new one BGAppRefreshTask() but every example is using actual-time like this:
request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) // Fetch no earlier than 15 minutes from now
but my current source used backgroundFetchIntervalMinimum like...
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
so how can I apply backgroundFetchIntervalMinimum with BGAppRefreshTask?
Setting the request’s
earliestBeginDateis equivalent to the old minimum fetch interval. Just useearliestBeginDatelike you have seen in those other questions. And when your app runs a background fetch, you just schedule the next background fetch with its ownearliestBeginDateat that point. That is howBGAppRefreshTaskworks.If you are asking what is equivalent to
UIApplication.backgroundFetchIntervalMinimum, you can just setearliestBeginDatetonil. The documentation tells us that:The latter caveat applies to
backgroundFetchIntervalMinimum, too. Background fetch, regardless of which mechanism you use, is at the discretion of the OS. It attempts to balance the app’s desire to have current data ready for the user the next time they launch the app with other considerations (such as preserving the device battery, avoiding excessive use of the cellular data plan, etc.).The
earliestBeginDate(like the olderbackgroundFetchIntervalMinimum) is merely a mechanism whereby you can give the OS additional hints to avoid redundant fetches. E.g., if your backend only updates a resource every twelve hours, there is no point in performing backend refreshes much more frequently than that.