iOS Network.framework does not connect to local network without default route on iPhone

Hi Quinn, I am developing an app that connects to a local device via Wifi or Ethernet.

I am using tcp over Network.framework for the communication. My network connector is configured as such for iOS:

let tcp_params = NWParameters.tcp
        tcp_params.preferNoProxies = true
        tcp_params.acceptLocalOnly = true
        tcp_params.prohibitedInterfaceTypes = [.cellular]

So what happens is that everything is fine as long as both the iPhone and the device are connected to an AccesPoint. But there is another option where the device acts as AccessPoint and you can join that network straight. The device, since it has no connection to the internet, does not offer a default route - so that any client devices can still use cellular network to access the internet.

What happens though is that I cannot get a connection to that device in case cellular data is on. The state handler shows the following error message:

lC3 MINI-20001._cap._tcp.local. tcp, no cellular, prefer no proxy, attribution: developer, path unsatisfied (Denied over cellular interface), interface: pdp_ip0[lte], ipv4, ipv6, expensive]

As soon as I disable cellular data, everything works fine. Is there any way to get around this? There must be cause Safari can actually connect to the device even with cellular data on.

I have played with various ways to configure the NWParameters, but no luck.

Maybe you got the magic?

Cheers, Michael

How are you connecting? By IP address? Or by a .local DNS name?

Share and Enjoy

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

        // Never use the cellular interface

        let tcp_params = NWParameters.tcp

        tcp_params.prohibitedInterfaceTypes = [.cellular]

        

        if config.useBonjour {

            Log.network.notice("Starting NetworkHandler with Bonjour for \(String(describing: config.name), privacy:.public)")

            

            let endpoint = NWEndpoint.service(name: config.name, type: "_cap._tcp", domain: "local", interface: nil)

            nwconnection = NWConnection(to: endpoint, using: tcp_params)

        }

        else {

            let host:NWEndpoint.Host = config.host

            let port:NWEndpoint.Port = 5055

            Log.network.notice("Starting NetworkHandler for \(String(describing: host), privacy:.public) at port: \(String(describing: port), privacy:.public)")

            nwconnection = NWConnection(host: host, port: port, using: tcp_params)

        }

Ha! I figured it out...

When the App has the "Mobile Data" setting turned off in Settings, then I need to disable Mobile Data for the App to connect to the local Wifi.

If I turn mobile data on though - everything works as expected.

This sounds a bit like a bug in iOS to me, tbh.

Cheers!

This sounds a bit like a bug in iOS to me

I can’t disagree. Please file it as such. Make sure to include a sysdiagnose log:

  1. Install the Network Diagnostics (for iOS) profile before you start.

  2. Reproduce the problem.

  3. Immediately after that, trigger the sysdiagnose log.

See our Bug Reporting > Profiles and Logs for more info about steps 1 and 3.

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"

iOS Network.framework does not connect to local network without default route on iPhone
 
 
Q