I'm working on an iOS app where I'm trying to implement a feature that detects when the currently connected wifi network has changed and executes some code in response to that change (nothing huge like updating a database or making api calls, just some quick local code).
I've looked at NWPathMonitor, which seems to accomplish this when the app is open in the foreground, but I'd like to have the same functionality when the app is in the background or suspended.
I've tried using BGTaskScheduler for this, but I don't find it reliable enough to schedule my network 'checks' to really be usable. Sometimes when a task is scheduled, it doesn't get run for example.
I'm aware of other background processing use-cases that Apple exposes, but I feel the functionality I'm aiming for doesn't fit things like background push notifications, deferred code execution, or long running tasks for example.
Is there a reliable way to be sure that my code is ran when the active network changes?