Monitoring for network changes while backgrounded or suspended

Detecting New WiFi Connection + WiFi Details

What I want to accomplish:

The app, including when backgrounded or suspended, creates a local notification (assuming the app has permission for notifications) when there is a new WiFi network being used and ideally being able to execute some small code to customize the notification. This code would also have access to SSID info, security type, etc., so the sort of info in NEHotspotNetwork. A number of apps seem able to do this but I am having trouble replicating what they are doing.

What I’ve looked at or tried:

Looking at “TN3111: iOS Wi-Fi API overview” https://developer.apple.com/documentation/technotes/tn3111-ios-wifi-api-overview

Navigate an internet hotspot (NEHotspotHelper)

Doesn’t look like NEHotspotHelper would provide the above functionality for detecting changes while backgrounded and it seems to indicate that the special entitlement com.apple.developer.networking.HotspotHelper would not be granted for this use case anyway.

Add an accessory to the user’s network

(Wireless Accessory Configuration (WAC) or HomeKit) Doesn’t seem relevant to my use case

Peer-to-peer networking

Doesn’t seem relevant to my use case

Location tracking

I don’t want to know my user’s location and Lookout and Norton 360 (just two of many examples) don’t request or have location permissions (or request any permissions for that matter except notifications) and are still able to obtain the WiFi network info without it as well as detect changes in the background.

Current Wi-Fi network

NEHotspotNetwork .fetchCurrent(completionHandler:)

So this is the most obvious since it returns the info I want but it requires the following permissions or configurations that neither Lookout or Norton 360 are requesting and also I don’t see how this API would trigger a backgrounded app to run, more for when your app is in the foreground and able to run already.

From Apple docs: “This method produces a non-nil NEHotspotNetwork object only when the current network environment meets all four of the following critieria:

  • The app is using the Core Location API and has user’s authorization to access precise location.
  • The app used the NEHotspotConfiguration API to configure the current Wi-Fi network.
  • The app has active VPN configurations installed.
  • The app has an active NEDNSSettingsManager configuration installed.

This method also requires the app to have the Access Wi-Fi Information Entitlement, and produces nil if the app lacks this entitlement.”

Once again, apps that are able to do what I want don't seem to have location permissions, no VPN profile, no DNS config, no hotspot config....

Additional things I’ve considered that are not mentioned in the above:

Using NWPathMonitor works for identifying a change, doesn’t trigger when app backgrounded and no access to SSID or other WiFi info.

What am I missing? Is there some API that I totally missed?

Thank you!

Colin

Replies

The app, including when backgrounded or suspended, creates a local notification (assuming the app has permission for notifications) when there is a new WiFi network being used and ideally being able to execute some small code to customize the notification …

Is there some API that I totally missed?

No. There’s no general mechanism to resume (or relaunch) your app in the background when the Wi-Fi network changes.

There is a mechanism that can do this sort of thing — see Local Push Connectivity — but it’s not really designed for your use case, meaning that you probably won’t be able to get the managed entitlement required to use it.

Share and Enjoy

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

  • Thanks Quinn for responding. Is there some way for me to check which special entitlements an app in the App Store has (i.e. not one of mine) so I can figure out how they were able to do this? Two apps in particular are doing exactly what I want to do, same use case basically, so if they used the local push connectivity entitlement it would bolster my request for the special entitlement.

    Thanks, Colin

Add a Comment