I have a method implemented thats tests the internet connection in my iOS app. The problem is, I only want the method to test the internet connection over wifi, not cellular. How do I do that? 🙂 PS I’m using the latest version of Xcode & iOS 6.
NSURL *scriptUrl = [NSURL URLWithString:@"http://10.247.245.87/stores/test.html"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data != nil){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Success"
message: @"You're connected to the server"
delegate: self
cancelButtonTitle: @"Close"
otherButtonTitles:nil];
//Show Alert On The View
[alert show];
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Connection Failed"
message: @"Please connect to network and try again"
delegate: self
cancelButtonTitle: @"Close"
otherButtonTitles:nil];
//Show Alert On The View
[alert show];
}
Have you looked into the Reachability class?
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
It will probably provide you with a lot more flexibility and why roll your own if Apple has already done the work 🙂 Hope this helps!