How to make a network judgment on iOS

Source: Internet
Author: User

Because the work is too busy in recent time, the blog has not been updated for some time, now to talk about the network judgment, if there are errors please the Great God can point out to learn together, thank you! Here's how it goes:

1. Add a source file (two): http://code4app.com/ios/Reachability/509743dc6803fae669000000
2. Import frame [systemconfiguration.framework]


3. Create a network connection
3.1 Creating an Internet Connection object
reachability *reach1 = [reachability reachabilityforinternetconnection];
3.2 Creating a local WiFi connection
reachability *REACH2 = [reachability Reachabilityforlocalwifi];
3.3 Creating a server network connection (important)
reachability *REACH3 = [reachability reachabilitywithhostname:@ "www.baidu.com"];


4. Judging the network
-(BOOL) isreachable; is available
-(BOOL) Isreachableviawwan; Whether Wwan is available
-(BOOL) Isreachableviawifi; Is WiFi available


5. Start notification
[Reach1 Startnotifier];


6. Registration Notice
Registration Notice
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (networkchange:) Name: Kreachabilitychangednotification Object:nil];


7. Cancellation Notice
[[Nsnotificationcenter Defaultcenter] removeobserver:self name:kreachabilitychangednotification Object:nil];

How to make a network judgment on iOS

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.