 |
 |
|
 |
10-11-2008, 02:38 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Jul 2008
Location: Minneapolis, MN
Posts: 208
|
Check for Wifi?
I am nearly finished with an app that is 95% offline but does have an online component. With the iPhone this is no problem, it can connect anywhere.
But I'd like to check if an iPod Touch user can get to the internet. If not, I'd like to gray out and/or notify the user that the service is unavailable in their area.
If possible, I'd like to check if the user CAN get to the internet, not just if they are connected. Is there a way to programmatically see if they are in range of a wifi network? - again, not just check if they are currently connected to one. I've searched for wireless and wifi in the docs, but nothing useful came up, except, maybe, reachability. But I've seen other apps that do all kinds of wifi functions, including automatically connecting you to an available network.
This isn't a show stopper by any means, but if this is doable I'd love to implement it before I release the app.
Any help is appreciated!
|
|
|
10-12-2008, 11:26 AM
|
#2 (permalink)
|
|
New Member
Join Date: Sep 2008
Posts: 1,431
|
The reachability sample app shows how to do this.
|
|
|
11-06-2008, 12:10 PM
|
#3 (permalink)
|
|
New Member
Join Date: Sep 2008
Posts: 74
|
phoney, youve been a great help in the past. but I have been hacking away at the reachability app for 6 hours now. I stripped the app down so it only swaps an image depending on wifi status. but if I cop the files over accordingly, how can I affect a button in a subview with its own view controller? I have a rootviewcontroller, appdelegate, viewcontroller, and a view. I think this may be an easy question but Im stumped. This should be very easy considering some of the other things ive noodled!
cheers and thanks again phoney! bozie.tehwifistatusbuttonerchangerwanter
|
|
|
11-06-2008, 01:21 PM
|
#4 (permalink)
|
|
New Member
Join Date: Sep 2008
Posts: 1,431
|
I just added NetReachability.m/h to my project. I added the following code to NetReachability. I admit that this is a little cheesy. It's a one time only check but that will work correctly in many cases. I'm intending to change my code to create an instance of NetReachability and set the delgate and update my UI when the reachability status changes. Implementing the delegate callback seems simple.
Code:
+(BOOL)networkIsReachable:(BOOL)inByWiFiOnly
{
//Make sure we have a WiFi network up & running
NetReachability* _reachability = [[NetReachability alloc] initWithDefaultRoute:NO];
BOOL result = [_reachability isReachable];
if (inByWiFiOnly)
result = result && ! [_reachability isUsingCell];
[_reachability release];
return result;
}
|
|
|
11-06-2008, 01:34 PM
|
#5 (permalink)
|
|
New Member
Join Date: Sep 2008
Posts: 74
|
so how would I then check for connection in view.m? I just dont know the basic piece of code that calls that function or is it set in a global variable?
so can i do something like if(gloabalvar == 0) then dim the button?
cheers.bo
|
|
|
11-06-2008, 02:13 PM
|
#6 (permalink)
|
|
New Member
Join Date: Sep 2008
Posts: 1,431
|
After adding the code that I showed the following is what I do in my view controller's viewDidLoad:
Code:
// Check if the network is reachable and turn off the controls if not
if (! [NetReachability networkIsReachable:NO])
{
mStatusLabel.text = NSLocalizedString(@"WiFi is not available", @"no wifi status text in Pull/Push Connectivity");
mStatusLabel.textColor = [UIColor redColor];
mGetFileButton.enabled = NO;
mNetworkIsReachable = NO;
}
|
|
|
11-06-2008, 04:17 PM
|
#7 (permalink)
|
|
New Member
Join Date: Sep 2008
Posts: 74
|
by NetReachability.h.m you mean the Reachability.h.m file? then if
Code:
if (! [NetReachability networkIsReachable:NO])
is in the view controller i can access t a field in the view from the viewcontroller right... ill try when i get a chance, but now im late for dinner!
thanks a ton :kicks self: learn darn you!
cheers.bo
{added} nope I cant get it to work.. now im late for dinner !
please help me obi wan kenobi, your my only hope...
Last edited by roberthuttinger; 11-06-2008 at 04:35 PM.
|
|
|
03-11-2010, 10:17 AM
|
#8 (permalink)
|
|
Registered Member
Join Date: Feb 2010
Posts: 12
|
Reachability doesn't do what I need
I have a similar need, but Reachability doesn't seem to do it.
My app is intended for an iPod Touch connecting via WiFi to an adhoc network created by a WiSnap ( Wi-Fi RS-232 serial adapter iPhone Android BlackBerry Windows Symbian) that is essentially a WiFi-to-RS232 adapter. The WiSnap [hosts?] the adhoc network on 169.254.1.1.
I need to be able to tell (1) if the WiSnap is powered up and the adhoc network available, (2) if I can actually reach 169.254.1.1, and (3) if my socket connection is working.
Well, I modified the reachability sample program to go to 169.254.1.1 instead of Apple. I'll describe a scenario where, at some prior time, the iPod was connected to the adhoc WiFi network. I turn both iPod and WiSnap power off. I turn iPod back on. I run Reachability. It says that Rmote Host 169.254.1.1 is "Reachable WiFi". It says the same for TCP/IP routing and local WiFi. This is NOT TRUE. The power is still OFF to the WiSnap. There is NO adhoc network in existence.
When I go to Settings on the iPod and look at WiFi, it still lists the WiSnap on the the main Settings page ("WiSnap-3727" is the adhoc network name). If I touch and go to the Wi-Fi Networks view, there's still a check mark net to WiSnap-3727, but the signal strength icon is almost all grayed out.
So, I believe the Settings program knows there's not actually a connection at the moment. But Reachability doesn't.
To further test, I can change WiFi connections to my office LAN, which is obviously different from the WiSnap. When I do this and subsequently run Reachability, it can still find remote host 169.254.1.1 (this must be some OTHER host on my LAN, not the WiSnap. I'm not worrying about this.) It says TCP/IP routing works. However, for Local WiFi, it says "Access Not Available". This is *indeed* what I *expect*.
Now I change WiFi connections back to the WiSnap. Well, I can't do that without turning the WiSnap on. I do so. I connect with Settings app. I immediately turn WiSnap power back OFF before leaving Settings app. I exist Settings and run Reachability. It thinks I can reach WiSnap. So, it's not going 'far enough' determining reachbility.
IN ADDITION TO ALL THIS, what I really need is for my app to assist the user in switching between TWO different adhoc networks. One is the adhoc network between the iPod and the WiSnap. Another is a hypothetical adhoc between the iPod and a lone Laptop. For test purposes, I can use my office WiFi LAN in lieu of the lone Laptop. Either way, I want my app to be able to SWAP connections between the two networks.
|
|
|
03-12-2010, 08:18 PM
|
#9 (permalink)
|
|
Registered Member
Join Date: Jan 2010
Posts: 76
|
I had a similar problem a while back and an awesome individual helped me out with it, so I'll return the favor to someone else. In this particular case you'll be checking if you're connected to a WiFi network. It will not test to see if you actually have access to the internet. You need to implement different means of testing for that (for example if you are using UIWebView's, you can use didFailLoadWithError method to take care of that.)
1) Import Reachability.h/m into your project
2) Add the SystemConfiguration Framework to your project
3) In your AppDelegate.h file, #import Reachability.h add the following method declaration.
Code:
-(bool)connectedToWiFi;
4) Now lets implement this method we declared. Within your AppDelegate.m file, add the following code:
Code:
-(bool)connectedToWiFi
{
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
bool result = false;
if (internetStatus == ReachableViaWiFi)
{
result = true;
}
return result;
}
5) Now depending on what you want to do if there is WiFi connection or not, there are several ways to go from here. The most common way of implementing the result is within the applicationDidFinishLaunching method within your AppDelegate.m file. In order to do that, just put in a simple if statement like such:
Code:
if( [self connectedToWiFi] )
{
NSLog(@"It works");
}
else
{
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No WiFi Connection" message:@"This App requires internet\n connection via WiFi. Please connect to a WiFi network\n and try again" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
}
Edit: Holy crap this is an old thread! We have some thread diggers in this forum. lol
Best regards,
-A.J.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 616 |
| 51 members and 565 guests |
| 63wagon, Akshay Shah, albi, Blitfast, boopyman, chaoz1337, ChrisMayer, crabFish, Craig2, Cubben2, dave1619, digidan, DonomaGames, dre, dtm, gc2010, Gendarme, Gravitation, Grinarn, harrytheshark, ianian, jbro, keuminotti, Kroupy, margalit, mgilani, moe, msudan, m_kaminsky@yahoo.com, nestle001, odysseus31173, p machine, panzeriti, PhotoShootoutApp, Pilly170, plus size cargo pant, psilocybin, RCummi86, Robyn, ronm3xico, Rudy, Ruenzuo, shuz, Straathond, tabanyi, umarmara, vikinara, Vonswanko, ZunePod |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 23,872
Threads: 38,649
Posts: 169,645
Top Poster: smasher (2,547)
|
| Welcome to our newest member, RCummi86 |
|