How to make requests to use cellular or WiFi when using GRPC for communication during iOS development

When developing a feature, we use GRPC for communication, and the phone needs to use cellular for external network access, as well as local WiFi access (WiFi cannot access the external network).

When developing a feature, we use GRPC for communication, and the phone needs to use cellular for external network access, as well as local WiFi access (WiFi cannot access the external network).

I haven't specifically tried this, but I believe you can make this work by using two URLSession with different session configurations:

  1. Your cellular session is configured to with allowsCellularAccess=true and with one of the "multipathServiceType"s set. I'm not sure which service type would work best (NSURLSessionMultipathServiceTypeInteractive vs. NSURLSessionMultipathServiceTypeHandover), that depends on your exact configuration/use case. Practically speaking, I'd experiment with both and use whichever one gave you the best result.

  2. Your local Wi-Fi session is configured with allowsCellularAccess=false and NSURLSessionMultipathServiceTypeNone.

If everything works as I'd expect, the cellular session will "try" to connect on both interfaces, fail on WiFi, and then route everything over cellular. The local Wi-Fi session will then route everything directly to Wi-Fi.

The other option here would be the Network.framework, since it does give you direct control over exactly which interface to use for every connection. However, I don't think this is a reasonable approach unless you have a GRPC implementation that already works with the Network.framework (or can easily be adapted).

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

How to make requests to use cellular or WiFi when using GRPC for communication during iOS development
 
 
Q