Some lines of code? Any experience?
Asked
Active
Viewed 4,021 times
0
-
possible duplicate of [iOS Detect 3G or WiFi](http://stackoverflow.com/questions/7938650/ios-detect-3g-or-wifi) – James Webster Dec 16 '13 at 15:49
3 Answers
4
You can use Apple's Reachability code to retrieve this information:
Example:
Reachability *reach = [Reachability reachabilityForLocalWiFi];
[reach startNotifier];
NetworkStatus stat = [reach currentReachabilityStatus];
if(stat & NotReachable) {
//not reachable
}
if(stat & ReachableViaWiFi) {
//reachable via wifi
}
if(stat & ReachableViaWWAN) {
//reachable via wwan
}

Jacob Relkin
- 161,348
- 33
- 346
- 320
1
Apple's Reachability
class will give you this information.
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

makdad
- 6,402
- 3
- 31
- 56
0
Since than I made a pretty simple block based Reachability wrapper that strips all the outdated C-like Reachability code, poured into a much more Cocoa form.
Usage like:
[EPPZReachability reachHost:hostNameOrIPaddress
completition:^(EPPZReachability *reachability)
{
if (reachability.reachableViaCellular) [self doSomeLightweightStuff];
}];
See Reachability with blocks for everyday use at eppz!blog, or grab it directly from eppz!reachability at GitHub.
It also works with IP addresses, which turned out to be a pretty rare Reachability wrapper feature.

Geri Borbás
- 15,810
- 18
- 109
- 172