Checking for Internet Connection on iphone upon entering a view
I am looking for a way, to check if my user is connected to the internet / cellular data when they navigate to a certain view of my application. I want this to occur pretty much when they press the button to take them to that view so the following occurs;
- If they do have internet connectivity, it loads up a UIWebView which a coded in URL.
- If they do not have internet connectivity, then it displays a static image instead.
First of all I guess i want to know if this is possible, and secondly the most efficient way o开发者_StackOverflow中文版f handling it.
Thanks
The way most of us deal with this is by using the Apple-written piece of code called Reachability. It can both pro-actively test for network connectivity, and set up a watcher to notify you when network connections status changes.
In the sample project behind that link, you want to bring the Reachability.m and .h into your project, then use the AppDelegate as a demonstration of how to use it.
精彩评论