Use Cellular To Transmit Data Instead of WiFi

Hi Guys,

I wrote an APP to transmit data through UNIX POSIX APIs, and if the mobile is connected to a WiFi, data will always be transmitted through the WiFi.

I want to transmit data via cellular in some circumstances. For example, when the WiFi signal is poor, the APP will try to use cellular without turning off WiFi connection.

Are there any ways to do this? Thanks!

transmit data through UNIX POSIX APIs

If you are using a low level networking API with TCP or UDP then you could take a look at requiredInterfaceType on NWConnection. For example, something like this may be what you are looking for:

Code Block swift
let tcpOptions = NWProtocolTCP.Options()
let params = NWParameters(tls: .init(), tcp: tcpOptions)
params.requiredInterfaceType = .cellular
params.prohibitExpensivePaths = false
params.prohibitedInterfaceTypes = [.wifi]


Which in the POSIX world would be similar to setting socket options with IP_BOUND_IF.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Thanks for your reply.

I have another question: How to deal with local DNS resolving?

If I set IPBOUNDIF to bind socket to Cellular interface, it only work on the data transmitted through this socket. How to make local DNS go through Cellular too? Currently, I use getaddrinfo for DNS resolving.
Using the BSD resolve-then-connect approach with getaddrinfo does not work with scoped networks. You could look into using NWConnection or nwconnectiont for this is you need to make a UDP connection with a scoped network. I suspect that will give you a better outcome.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Use Cellular To Transmit Data Instead of WiFi
 
 
Q