NWPathMonitor and mobile router WiFi without SIM always get connected

Hello, I'm looking for a way to detect using NWPathMonitor when the iOS device is connected to a router but not to the internet. As an example a mobile router WiFi without SIM.

In settings I'm able to switch the connection to its WiFi, once connected a label below the SSID shows Not connected to the internet. I would like to show the same thing to the user inside my app, but unfortunately I always get the satisfied answer.

Am I missing something in configuring NWPathMonitor or reading the answer?

final class InternetConnectionMonitor {
           
    lazy var internetConnectionStatusPublisher: AnyPublisher<InternetConnectionStatus, Never> = {
        _internetConnectionStatusSubject
            .compactMap{ $0 }
            .eraseToAnyPublisher()
    }()
    
    var lastInternetConnectionStatus: InternetConnectionStatus? {
        _internetConnectionStatusSubject.value
    }

    private let _internetConnectionStatusSubject = CurrentValueSubject<InternetConnectionStatus?, Never>(nil)
    
    private let pathMonitor = NWPathMonitor()
    private let pathMonitorQueue = DispatchQueue(label: "com.xxxxx-network-monitor", qos: .default)
    
    init() {
        startPathMonitoring()
    }
    
    private func startPathMonitoring() {
        pathMonitor.pathUpdateHandler = { [weak self] path in
            guard let self else { return }
            let networkStatus = InternetConnectionStatus(from: path)
            self._internetConnectionStatusSubject.send(networkStatus)
        }
        pathMonitor.start(queue: pathMonitorQueue)
    }
}

When you run this test, is the iOS device connected to Internet via WWAN?

Share and Enjoy

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

I need to clarify your setup here.

First up, are you using Personal Hotspot?

I don’t think you are, so presumably there are two bits of hardware in play here:

  • Your “mobile router WiFi without SIM”

  • Your iOS device

My previous question was about the iOS device. Many iOS devices support both Wi-Fi and WWAN; think iPhone and iPad (Wi-Fi + Cellular). Is that the case here? If so, is the WWAN functioning when you run this test?

Share and Enjoy

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

Thanks for the clarifications.

If you initialise your NWPathMonitor using init(requiredInterfaceType:) and specify an type of .wifi, do you see different behaviour?

IMPORTANT I’m not suggesting this as the ultimate path forward; it’s just a diagnostic test.

Share and Enjoy

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

Hello Quinn sorry for for getting back to you late. I tried but still is giving me satisfied as an answer. I also tried with different mobile router each one without SIM, but the answer is the same. Thank you, Andrea

Thanks for running that test.

I’m pretty much out of ideas here, so I’d like to take a step back. Earlier you wrote:

I would like to show the same thing to the user inside my app

Is that the only thing you intend to do with this state?

Share and Enjoy

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

@eskimo ok the whole context is a little bit more complicated. We have 3 components to check if internet is available and our server is in a healthy status and reachable.

  • The internet monitor
  • A check on our status page that defines if the server is working properly
  • A check on an endpoint to see if the server is reachable

Use cases

  • If the device is not connected we notify the user
  • If is connected but without internet we notify the user (this is something that at the moment we cannot do)
  • If one of our request fails for some URLErrors we start to check our server status page. If something is not working we say the user the "we are experiencing problem"
  • As a plus we check the reachability of an endpoint (it could happen that some network can access the status page but not the backend endpoint)

At the moment if we are in a situation like the one mentioned before due to the fact that we cannot have the state connectedWithoutInternet we fallback on some URLError and start the process of checking our server that of course fail thus the user is informed, but the message we are sending is that we have a problem, while the resolution of the issue could be "try to connect to another network" because you don't have internet.

This is not very optimal I would love to have something like in iOS settings when I connect to this kind of network Is there a way to configure NWPathMonitor to receive the same information?

A check on an endpoint to see if the server is reachable

By “endpoint” you mean something running on your server, right? So that involves making an HTTP[S] to your server and checking the result.

Share and Enjoy

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

Exactly, the first check :

  • A check on our status page that defines if the server is working properly

We get a json that defines the status of our server on each different macro services (authentication resource access, etc) with operational, downtime, issues

The second check:

  • A check on an endpoint to see if the server is reachable

is made only if the first one succeed and yes this is more of a reachability of our APIs endpoints, just expecting a body with ok. If the request goes on timeout or cannot find the host there is probably something blocking the outgoing connection.

We applied this further control due to the fact that the domain of the first check is different from the second and we experienced some issues where the user had reachability of the first one, but not on the second due to firewall rules blocking requests to api.xyx domains.

Best, Andrea

I admire your commitment to updating the user with accurate status!

Anyway, at this point I’m going to suggest that you file a bug about this. In general, tools like NWPathMonitor base their answers on local state, which puts limits on what they can do. However, the fact that Settings shows this state indicates that it should be possible for NWPathMonitor to factor it in, and I think it’s reasonable to ask for that.

Please post your bug number, just for the record.

Share and Enjoy

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

NWPathMonitor and mobile router WiFi without SIM always get connected
 
 
Q