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)
    }
}

Replies

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"

  • Hello Quinn, actually I'm not so sure about how to reply.

    The device I'm using as a router doesn't have a SIM card but still provides a LAN among connected devices, but as stated by iOS settings no internet connection is available. So I think that by removing the SIM it won't provide a WWAN. I don't know if it makes sense on a networking standpoint.

Add a Comment

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"

  • I got it. I can confirm that I'm not using a hotspot.

    I'm using a mobile router WiFi without SIM.

    I'm using an iPhone 8 without SIM as well connected to the mobile router, so even if where is a possibility of WWAN due to the fact that the SIM card is removed inside the phone I think I'm not using it.

    I hope this clarify the whole set up.

    Thank you so much for your support, Andrea

Add a Comment

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?