Please note that all pointers to Reachability are a good start, and you definitely need the opportunity to upgrade, but for a messaging application this is usually not enough. Reach never sends packets. It just tells you if the device can even try to send a packet if you ask for it. So it basically tells you that you have an IP address and you know the gateway. It does not tell you that you can contact the server you care about, and it does not tell you at all whether this server can contact you (which is a very important issue for messaging applications).
In most cases, if Reach was sufficient, you won't need Reach. Apple strongly recommends (and not in vain) that you do not check Reach before sending packages. Just send the packets and handle the error if it appears. But this does not help applications that should receive data at arbitrary points in time.
If the connection is poor (especially due to poor cell coverage), or if there is a firewall between you and the server, you can easily get positive results from Reachability, even if you no longer receive messages from the server. The only way to detect this situation is to send a packet and receive a packet (ie "Ping").
Reachability is also insufficient to notice when your connection changes. For example, if you change IP addresses (quite often when you are driving around town), Reachability will not always tell you (maybe if you use SCNetworkReachabilityCreateWithAddressPair() , this has been a while since I worked on this problem; example code Reachability doesn't work that way anyway).
So, Reachability is a good first start, but at the end of the day you still need a heartbeat if you want to discover that the server is no longer talking to you. The main thing to remember is that there is no such thing as a βconnectionβ in IP. There are only packages. You can send them, and you can receive them. But if you do not accept them, there is no way to distinguish "no one sends them" from "they do not arrive." The TCP illusion gives "connections" only when packets are exchanged.
(By the way, working with a network connection in a messaging app is probably the most complicated iOS code I've ever worked with. Testing is a nightmare. I used my phone in the refrigerator to disable its network access. Now there is network air conditioning ...)
source share