IOS: network detection

Source: Internet
Author: User

If you want the app to pass the review, you must determine the network environment and handle alerts when there is no network.

Apple's routine reachability describes how to obtain/detect the network status. To be appliedProgramTo use Reachability in a program, you must first complete the following two parts:
    
    1.1. Add the source file:
    In your programUse ReachabilityYou only need to copy the reachability. h and reachability. m in this routine to your project. For example:

       
       
        1. 2. Add the framework:
        Set systemconfiguration. Framework Add to project. For example:
       
       
        2. Network Status
       
        Three Network statuses are defined in reachability. h:
        Typedef Enum {
                Notreachable = 0,                       // No connection
                Reachableviawifi,                       // Use a 3G/GPRS network
                Reachableviawwan                       // Use a Wi-Fi network
        } Networkstatus;
       
        Therefore, you can check the network status as follows:

        Reachability * r = [reachability reachabilitywithhostname : @" Www.apple.com "];
        Switch ([R currentreachabilitystatu S]) {
                        Case notreachable:
                                        // No network connection
                                        Break;
                        Case reachableviawwan:
                                        // Use a 3G network
                                        Break;
                        Case reachableviawifi:
                                        // Use a Wi-Fi network
                                        Bre AK;
        }

Check: http://blog.sina.com.cn/s/blog_6f40a0e70100srip.html

Related Article

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.