iOS Development-Network monitoring

Source: Internet
Author: User

Network listening to the class for Reachability.h, this Xcode project is not self-contained, need to download from GitHub, when used to remember to import systemconfiguration.framework.

The first is to set up network monitoring in APPDELEGATE.M.

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (reachabilitychanged:) Name: Kreachabilitychangednotification Object:nil];

Initialization

_reachability = [reachability reachabilityforinternetconnection]; [_reachability Startnotifier]; [Self updateinterfacewithreachability:_reachability];
Implement two methods:
-(void) reachabilitychanged: (nsnotification*) note;//network connectivity Changes
-(void) Updateinterfacewithreachability: (reachability*) curreach;//processing after connection change
The following is a concrete implementation of the method, which can be changed according to the circumstances:
Connection change-(void) reachabilitychanged: (nsnotification*) Note {    reachability* Curreach = [Note Object];    Nsparameterassert ([Curreach iskindofclass: [reachability class]]);    [Self Updateinterfacewithreachability:curreach];} After processing the connection changes-(void) Updateinterfacewithreachability: (reachability*) Curreach {    ////response to the connection change.    networkstatus status = [Curreach currentreachabilitystatus];        if (status = = notreachable) {        _isreachable = NO;        No connection to the network pops up live        uialertview *netalert = [[Uialertview alloc] initwithtitle:@ "cellular data Closed" message:@ " Enable cellular data or wireless LAN to access data "Delegate:nil cancelbuttontitle:@" OK "otherbuttontitles:nil";        [Netalert show];    } else {        _isreachable = YES;    }}

iOS Development-Network monitoring

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.