I need to connect an iOS device (iDevice) to a WiFi access port but keep using the cellular data connection.
Default behavior is for iOS to set the WiFi connection as the default gateway, routing all internet traffic there. In my case the access point is a black box device supplying a WiFi network to access it's services, but not the internet.
One solution which we have tried, is to make the iDevice the access point (hot spot) and have the black box device connect though it. This is far less desirable as the black box device has no UI. So it is difficult to setup. We have lessened the pain by using Bonjour but still...
Is it possible to make a system call (iOS application) to restore the gateway setting back to the cellular gateway after the iDevice joins a WiFi network?
Would be even better if there is some way to setup the iDevice (IPhone or IPad) to maintain it's cellular gateway after connecting to a WiFi access point.
Related
Is it possible to access internet (using cellular) during WiFi device configuration using Apple's "Wireless Accessory Configuration" feature?
This device would create the WiFi network and we would need to get data from the server while configurating the device.
Specifications:
Would iOS automatically use cellular to connect to the internet if there is no internet connection through WiFi? (But still keeps WiFi connection with device)
Or is it possible to programmatically switch between connections? For example: Get data from device through WiFi, send data to server through cellular, get data from server through cellular and then configurate device through WiFi.
Some other way to accomplish this?
From Apple Developers Forum:
eskimo:
"iOS keeps WWAN active even when Wi-Fi is fully functioning. That’s done because important system services, like push notifications, always run over WWAN where possible.
So, what you’re asking about is the switch of the default route. In general, iOS only switches the default route to Wi-Fi when the Wi-Fi is fully up and running. That means that WWAN should remain the default route during the WAC process."
https://forums.developer.apple.com/thread/46528
Scenario: I want to have an iOS device connect to a LAN that has no upstream Internet connection, yet still retain and use its cellular data connection.
Theoretically, it strikes me that the iOS wifi NIC and the cellular data NIC are similar enough to dual NICs in a PC that I should be able to set up routing such that any request to, say, 192.168.. goes through the wifi connection, and any other request goes through the cellular data connection.
I did a test to see if both NICs are active when the iOS device is connected to wifi by the following steps.
Ensure that my iPhone's wifi is off and that I have a good cellular data connection.
Disconnect my wifi router's Ethernet cable to my cable modem.
Connect my iPhone to the wifi router.
Use another iPhone that's connected only via cellular data to create a game of Words with Friends.
As soon as the other iPhone completed the first move, my iPhone received a notification that there was a new game to play.
This confirmed that the cellular data connection was indeed alive and well enough to receive push notifications despite the wifi NIC's being connected.
The question becomes, then, can an app programmatically connect to a given wifi network, set the cellular data network to be the default route, and route any requests to, say, 192.168.. to go through the wifi network?
I know this post is old, but I happen to have done some work on using multiple network interfaces on iOS.
My experiments showed that accessing via hostname results in iOS choosing the network interface it wants to use, and not trying any further interfaces if the host cannot be resolved.
If you know the DNS Server IP address for any Ethernet/WiFi based network, you can send a DNS request yourself, convert the hostname into an IP address and access via IP address. iOS will then use the correct interface.
My guess is, that if you have the private class IP address space accessible over both connections, there's probably nothing you can do to specify which network interface should be used.
When I tether my mobile network to laptop with Hotspot on iPhone and test for Reachability's currentReachabilityStatus it reports ReachableViaWiFi where neither Wifi is open nor is it sharing mobile network via Wifi.
I know even with this, it shows correct information on internet connectivity but the nature of my app requires exact information on whether Wi-fi is connected or not so its not the issue to determine internet connectivity but more of Wi-fi reachability.
x----x----x----x----x----x----x
EDIT:
Infact it fails if there is no device connected on USB. Only reports ReachableViaWiFi when a machine is using its internet via USB.
Open this post: detect hotspot enabling in iOS with private api's
Maybe enumerating network interfaces will let you discover the fact that connection is actually a tethered cellular network.
Don't worry that title includes private API - the solution contains also a way to this without using private API.
BACKGROUND
We're trying to use an iOS app running on iPhone/iPad to give WiFi credentials to an embedded device (using an ARM SoC running Linux). The embedded device starts an AP (access point), we instruct the user to connect to this AP and then the user submits their WiFi credentials. After WiFi credentials are received the device drops the AP and connects to the WiFi the user gave credentials for.
Initially, we try to hit a PHP page to get the list of WiFi networks the embedded device can see.
ISSUE
We instruct the user to join XYZ network (in iOS they must background the app, go into settings and switch to our WiFi network). We listen for an app resumed from background notification, check the devices current ESSID (ensure its our AP ESSID) and try to hit a PHP page to receive the list of WiFi networks. Often, this connection fails reports "The internet connection appears to be offline" (or something of that nature).
We currently have a stop gap when this happens telling the user to toggle their WiFi off and then back on (in settings). The device will reconnect to our AP as it's the most recently connected network. This ALWAYS fixes the issue, we've never had to toggle the WiFi twice in order to reach the PHP page on the device. Please tell me any possible way we can avoid having to instruct the user to toggle WiFi and still access PHP pages on the embedded device.
Note: when we're connected to the AP (whether this bug is active or fixed) the device DOES NOT show the WiFi icon in the status bar. We assume this is because the AP doesn't have a viable connection to the internet (can only access pages served by the embedded device). We've been testing on a device that has LTE cellular access, but the error still says "Internet connection appears to be offline".
Obviously we have a DHCP server running on the embedded device.
It's looking like this was caused by an omission in our dhcpd.conf file.
This omission was causing iOS to believe the connection was unviable.
We added the following line and are getting much better results:
option domain-name-servers 10.10.10.1;
Assume a device was offline with no service neither WiFi to begin with, is there a callback/delegate to tell that the device is back to be connected once the service or WiFi is available? or do we have to proactively pull the status?
You could check it with the Rechability class:
The Reachability sample application demonstrates how to use the SystemConfiguration framework to monitor the network state of an iPhone or iPod touch. In particular, it demonstrates how to know when IP can be routed and when traffic will be routed through a Wireless Wide Area Network (WWAN) interface such as EDGE or 3G.
here is an Example