iOS SimplePing gives incorrect result at times - ios

To sign in and access various functions of our iOS app, the user needs to be connected to our VPN network from their iOS devices. The webservices that the app calls are also only accessible over VPN. In order to determine if the user is running the app over VPN (online mode) or if the user is running the app outside of VPN (offline), we are using Apple's SimplePing class helper https://github.com/chrishulbert/SimplePingHelper. We pass the host name of our web services to make the ping call. If it succeeds, we conclude user is on VPN. If the ping fails, we conclude the user is not on VPN and give him a message saying he needs to connect to VPN.
The issue we are seeing is that sometimes we get a ping failure even if the user is on VPN and this results in the user getting a message that he lacks connectivity. If the user tries some action again, the call succeeds.
We are not sure of what causes the pings to fail intermittently and succeed again when tried in a few seconds. Has anyone experienced this kind of an issue? What could be the possible cause and resolution? Any ideas are welcome.

We use SimplePing and I noticed that sometimes it fails to resolve the hostname (in -(void)hostResolutionDone) even before it gets to the actual ping. I haven't yet figured out why but my workaround was to stop/restart the ping service. The host resolution failure happens infrequently so it usually corrects itself the second go around.

Related

Make sure network request gets executed before app is uninstalled

I have a PacketTunnel Provider extension running with my app. Once a user un-installs the app I get a call "stopTunnel" with an identifiable reason.
Trying to send a last network request appears to fail. Yet I'm wondering if there might be any low level network options I should try before giving up on this quest?
Happy for suggestions even if they are un-verified. I can try them in my set up.

How to deal with local network changes (NSLocalNetworkUsageDescription) on iOS 14?

Our application connects to a local WiFi network (using TCPClient) for data communication purposes.
But in iOS 14 the connection fails completely because two processes take place at the same time:
TCP client initialization
Current network permissions
So the connection to the local network is blocked until we reopen the application.
To avoid this, we're doing a hack: Pinging to a local IP address triggers the current network permissions (this is done in the OnActivated() method of AppDelegate).
The connection only works properly if it is connected to that particular network otherwise it fails.
Has anyone faced this issue before? I appreciate any suggestions from the community.

"No route to host" error on iOS

I used GCDAsyncUdpSocket to send udp message to discover ssdp service, in iOS reported "No route to host" this error,but there is no problem in the simulator above can be found in service, is that how it happened? I searched a lot of information, but no discovery could help me.
I've run into the same thing. Of course without your source code we can't help you other than to provide vague guesses. I hope you've fixed it by now and if you recall what the problem actually was, please let us know.
Things to check :
Firewall settings on the host. I was trying to receive messages on my mac book and found that Firewall settings can block the port you chose. Firewall is under system preferences on the 3rd tab.
Use apples Reachability class to make sure you've got an active WIFI/Cell connection to the internet. (here : https://developer.apple.com/library/ios/samplecode/Reachability/Listings/Reachability_Reachability_h.html#//apple_ref/doc/uid/DTS40007324-Reachability_Reachability_h-DontLinkElementID_7 )
You can also use other functions in the Reachability class to let you know if the host is reachable before even bothering to open up a socket.
If the host is your mac and the simulator is on the mac, there isn't much of actual network traffic and then when you run on your phone you are actually using real networking. Be aware of, depending on your networking situation, you may need the external IP address of your host (vs the internal network WIFI address e.g. 192.168.1.4 )
Some people have reported a bug where UDP stops working and you get no route to host messages but for some reason turning on and off airplane mode fixes it. Maybe check out their solution (using keep alive messages ever 30 seconds or so to prevent power management from turning off the cell connection). Here is an example : intermittent "No Route to Host" on iOS, flight mode off then on fixes
In case you are developing an App Clip for iOS app, be aware that:
a) Background Session is not supported
b) Multipath is not supported. Setting `multipathServiceType = .handover` on `URLSessionConfiguration` will cause all requests failure due to `No route to host`

How to make iOS believe there is Internet Connectivity

I am working on a web application for iOS that is going to be accesed from a local webserver in a network that has NO internet connectivity at all.
My problem is that everytime an iOS device is locked, it disconnects from the WiFi network, so when the device is unlocked again, it has to reconnect. Part of that reconnection process is determining if there is Internet connection (which there isn't). Until the process is not finished iOS does not allow any DNS resolution (so if I write http://10.0.0.1 it will go there, but not if I request http://something.local.com).
Since we control that network, we want to know how to does iOS verifies Internet connectivity so that we can fake the responses it expects.
I don't know if it's possible to resolve DNS without an internet connection on iOS, but if that's the case, that would be a way better solution since you don't need to mess with your router settings. Use my solution only if it really isn't possible with only code.
I'll suggest you to follow this guide: http://blog.jerodsanto.net/2009/06/sniff-your-iphones-network-traffic to check which actions your iPhone executes to detect an internet connection.
Using this information you could forward the is-there-internet-requests on your router to a local server which fakes the there-is-internet-responses.
This assumes Apple really uses an external server to detect this, which I'm not sure about. But it wouldn't hurt to give it a try!
Have you looked at the Reachability Class? You don't have to use the reachabilityForInternetConnection method, which checks if a default route is available. You can use the reachabilityWithAddress: method and check if your server is reachable.

timeout error when on an ad hoc network

I am doing an InternetConnect (Wininet) to an FTP server that happens to be running on an iPhone. When the user is on a normal WiFi network it works fine for him. When he has an ad hoc network with his iPhone he gets an ERROR_INTERNET_TIMEOUT. I presume this is some kind of routing problem. I am curious as to why this gets ERROR_INTERNET_TIMEOUT and not ERROR_INTERNET_CANNOT_CONNECT. Most users, if they are blocked by, for example, a firewall, will get ERROR_INTERNET_CANNOT_CONNECT.
I don't understand enough about low-level TCP/IP to understand what kind of situation would cause a timeout error instead of a connect error. I'm really more intellectually curious in understanding this than I am in actually solving the user's problem. ;-) Can anyone explain what is happening with the network packets (the more detailed the better)?
edit:
note that, as far as I know, the user doesn't have an outgoing firewall enabled, it's not a firewall issue. I think it's some kind of routing issue. I have seen similar issues when a user is connected a VPN and their routing is set up incorrectly and all packets go to their work instead of the iPhone. I want to know what's going on with the packets in this situation: the socket connects but at the next step (whatever that is) they can't communicate.
Firewalls these days choose to not respond at all to packets that they deem suspicious, this is to prevent port scanners from detecting that there is a machine at the IP. So that could be what is happening in your case, the firewall may simply be dropping the packet and causing a timeout rather than a failure to connect error.

Resources