IPhone determines the current network status

Source: Internet
Author: User

1. Add the framework:

Add systemconfiguration. Framework to the project.

2. Download http://download.csdn.net/detail/svrsimon/4458137

Copy reachability. h and reachability. m to the project.

3. Called code:

-(Nsstring *) getcurrntnet
{
Nsstring * result;
Reachability * r = [reachability reachabilitywithhostname: @ "www.apple.com"];
Switch ([R currentreachabilitystatus]) {
Casenotreachable: // No network connection
Result = nil;
Break;
Casereachableviawwan: // use a 3G network
Result = @ "3G ";
Break;
Casereachableviawifi: // use a Wi-Fi network
Result = @ "WiFi ";
Break;
}
Return result;
}

The above code is tested on the simulator of the Virtual Machine. If there is an exception, cannot the simulator be used to test network connectivity?

In addition, no matter whether a network cable is inserted or not, the WiFi of the simulator is always connected, regardless of whether the network of the computer is disconnected (also in a virtual machine)
+ (Bool) isenablewifi {// always return YES
Return ([[reachability reachabilityforlocalwifi] currentreachabilitystatus]! = Notreachable );
}
3G/GPRS is always disconnected.
+ (Bool) isenable3g {// No is always returned
Return ([[reachability reachabilityforinternetconnection] currentreachabilitystatus]! = Notreachable );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.