Thank you @Tomato and @DTS Engineer !
The purpose of my app is to provide a notification mechanism when there are drastic air quality changes.
To accomplish this, I have an async function that makes a GET request to an air quality sensor (using UrlSession), decode the payload, and then do comparisons with previous readings. If the readings have changed drastically, an UNMutableNotificationContent() is scheduled.
Currently, my async function is called from within a repeating scheduled timer so that I can poll my sensor every minute:
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
timerVal -= 1
if timerVal == 0 {
timerVal = startVal
getAQI()
}
}
This all works just fine (including when the app is in the background) ONLY when I run the app from Build and Run in Xcode on my dev iPhone as the destination. I've left the app running this way for hours in the background and with the phone locked and it works great!
However, when I try to run the app purely from the app shortcut on my iPhone, it works fine when in the foreground but it no longer runs the Timer wrapped functions in the background.
@DTS Engineer - given your statement
Any Timer, DispatchQueue, or standard network calls you have running will freeze immediately.
Maybe it's a bug that Xcode allows myTimer to keep running in the background?
I am completely open to learning any way to accomplish the functionality I need. I've been reading about BGAppRefreshTask, but it sounds like it does not give me the time guarantee that I need to fetch critical data every x minutes and be notified in a possible approaching fire scenario.