Reachability reports Wifi when HotSpot is On via USB - ios

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.

Related

Can iOS application use cellular internet connection while doing "Wireless Accessory Configuration" through WiFi?

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

Is there a way to programmatically change network routes on an iOS device?

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.

Controlling default gateway on iOS

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.

Wifi connection when using mobile network

When I change my network from 3G to Wifi what is happening to all the services I'm using (like Facebook, Gmail, etc.)? Do they disconnect and then connect again? Is it like roaming between mobile networks?
Yes they are disconnected and they have to reconnect. I checked that in my own Android app. There I'm handling mobile and wifi network strength and on change the device is offline.
Since you change your connection you will get another IP which requires to reconnect.

Is there a callback/delegate to tell that the device is back to be connected (to carrier service or wifi) after offline?

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

Resources