IOS network with multi-threaded--1. Detecting Network link status

Source: Internet
Author: User

Check the network connection status of the device through the reachability library.

Class Library used: reachability

Reachability Library, is an iOS environment, the detection device network status of the library, you can search for downloads on the network.

Imported into the project before use.

Then add the following code within the View controller file (VIEWCONTROLLER.M)

Import the network State Library #import "Reachability.h"

1 //used to detect if the network has functions2-(BOOL) isexistencenetwork3 {4 BOOL isexistencenetwork;5     6     //test whether the network can connect to Apple's website. For friends who use IAP, you can use it to detect if you can connect to itunes. 7reachability *r = [reachability reachabilitywithhostname:@"http://www.apple.com"];8     //traversing a network connection9     Switch([R Currentreachabilitystatus]) {Ten          CaseNotreachable://indicates a state in which the network is unavailable.  OneIsexistencenetwork =FALSE; A              Break; -          CaseReachableviawwan://represents the network through the 2G/3G/4G link.  -Isexistencenetwork =TRUE; the              Break; -          CaseReachableviawifi://represents the current network over a Wi-Fi link.  -Isexistencenetwork =TRUE; -              Break; +     } -      +     returnisexistencenetwork; A}

Then add the test code inside the Viewdidload function:

1     BOOL canconnectnetwork = [self isexistencenetwork]; 2 3     NSLog (@ "Can Connect network--------%d", canconnectnetwork);

These are the features we want!

IOS network with multi-threaded--1. Detecting Network link status

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.