Using NSURLSession on a cellular network only is not a preferred option in iOS. Wi-Fi is always the preferred option for dataTasks and that is why you see options for providing access to WWAN, but not using it as your required path. For NSURLSession you would have to gate your dataTask execution around the usesInterfaceType result from NWPathMonitor. Which is essentially a preflight-check, something I typically recommend against.
let pathMonitor = NWPathMonitor()
pathMonitor.pathUpdateHandler = { path in
if path.usesInterfaceType(.wifi) {
print("Path is Wi-Fi")
} else if path.usesInterfaceType(.cellular) {
print("Path is Cellular")
} else if path.usesInterfaceType(.wiredEthernet) {
print("Path is Wired Ethernet")
} else if path.usesInterfaceType(.loopback) {
print("Path is Loopback")
} else if path.usesInterfaceType(.other) {
print("Path is other")
}
}
pathMonitor.start(queue: .main)
For Network Framework, when creating a NWConnection you can use NWParameters to specify the requiredInterfaceType of .cellular. As an example:
let params = NWParameters(tls: tlsOptions, tcp: tcpOptions)
params.requiredInterfaceType = .cellular
connection = NWConnection(to: connectionHostPort, using: params)
To test the failing case for the example above, make sure your Wi-Fi interface is on and WWAN is disabled.
Matt Eaton
DTS Engineering, CoreOS
meaton3 at apple.com