I am developing an application for the iPhone, and whenever I call my web service, I want to make sure that the user is connected to the Internet.
I used the Reachability class provided by Tony Million on github, the link is for everyone who wants to capture it. https://github.com/tonymillion/Reachability
I just followed the examples and set everything up and had the following code
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"]; reach.reachableBlock = ^(Reachability*reach) { // call web service here }; reach.unreachableBlock = ^(Reachability*reach) { // alert user not reachable }; [reach startNotifier];
Now I am testing this in a simulator, and everything works fine, my service is called when connected to Wi-Fi. And if I turn off Wi-Fi, I see a warning, which is exactly what I need.
Now I test it on the device and get decent results, but not quite what I need. It is important to note that my phone does not have a data packet.
So here is the script
- I connect my phone to Wi-Fi and run the application perfect, the call is made in the web service. There is nothing to worry about.
- I will disconnect my phone from Wi-Fi and run the application again. I WAIT for a warning to inform that it is not connected, but then I see a user interface activity indicator spinning in my application, which means that the application has detected some kind of connection and is trying to connect to my web service. But this will never happen, I know that it detects cellular 3G, when I go to settings -> general-> usage-> cellular, reset statistics is 0. After a while I see that the data is being sent and received.
- I go to settings-> general-> cell-> turn 3g off, start the application, and now it shows a warning about the impossibility of connecting.
I know that many people have data packages, and also I see that the applications hit the market with the reachability level that I mentioned above, I just feel that this can be improved in the scenario that I just explained.
I have a 3g connection, but I don't know how
[Reachability reachabilityWithHostname:@"www.google.com"];
receives ping, or maybe it is not?
Although I turned off Wi-Fi and opened the safari, it behaves the same, it shows that it has been loading for quite a while, and then just says that the safari cannot open ...
Is this something that cannot be achieved?
Finally, I even saw a sample, Tony Million, provided on the github page, when it runs on my phone, it shows that it is available, even though Wi-Fi is disabled and I don't have a data packet.
I looked at several answers on the stream where users asked about checking the Internet connection, but most of the answers either depended on the wifi type, wwan, etc., and did not find out if it is a real Internet connection, and not connected to the network.
Thank you for your time.