This is a discussion on How to check if there is internet connection on iPhone OS devices within the iPhone/iPad Programming Tutorials forums, part of the Programming Section category; Hey guys, Here I'll show you how to detect if there is no internet connection on iPhone device which is ...
Hey guys,
Here I'll show you how to detect if there is no internet connection on iPhone device which is using the device and give an error message if it's not there.
First you need to download the Reachability from apple's site.
1) Import Reachability.h, Reachability.m and CFNetwork, SystemConfiguration Frameworks to your project.
2) Import Reachability.h in your .m file by putting this code at start of your file:3) now inside your viewDidLoad insert this code:Code:#import "Reachability.h"This code will check if it can connect to google.com and if now will make a UIAlertView with title "No Internet Connection" and message "This app require an internet connection via WiFi or cellular network to work."Code:Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"]; NetworkStatus internetStatus = [r currentReachabilityStatus]; if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) { UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease]; [myAlert show]; }
That's itif you need any help implementing it, leave a replay.
Last edited by Fahad; 01-10-2011 at 12:11 PM.
MozyMac Founder,Chairman and CEO
MacBook Pro Unibody late 2008 2.4Ghz 4GB ram 250GB HD
MozyMac Youtube Channel
Just a quick note, this might crash if this is implemented in a controller other than the AppDelegate Controller, this because you are marking the alert window for "autorelease" and the you are calling the "release" method; thus; taking the "retainCount" below 0 since it was never retained.
You should either NOT mark it for "autorelease" or remove the "release" message.
Thanks for the share on this subject
Highly appreciated.
Last edited by Creegan; 10-06-2010 at 03:18 PM.
MozyMac Founder,Chairman and CEO
MacBook Pro Unibody late 2008 2.4Ghz 4GB ram 250GB HD
MozyMac Youtube Channel
Thank You its a Really Nice Service,I am not Aware with this Details.