IOS Monitoring Network changes

Source: Internet
Author: User

With the mobile network upgrade: 2G->3G->4G even the development of 5G, the network speed is more and more fast, but this flow is like flowing water generally rushing away.

Online is not a joke: sleep forgot to close the flow, the next day the house will be moved!

This is an exaggeration to say, but as a good app developer, we need to give the most appropriate hints in the app.

Give some hints when you need to spend a lot of traffic (for example: video, downloads, etc.).

When users switch the network during user video, give the prompt to continue watching!

The following author gives a real-time monitoring of the network status change Method!

I use the network to spread the widest network monitoring class: Reachability

Click here to download this demo: Click to download

Unzip the files downloaded above and add the Networkreachability folder to the project you need to add.

Example Description: This example demonstrates how to use the Systemconfiguratio Reachalility program interface to determine the associated network connection status and state transformation , so using the reachability in this example . (h/m) file in its own project is premised on the need to introduce systemconfiguration.framework.


Import header file:

#import "NetworkReachability.h"

Defining Global Variables

Networkreachability *_netreachability;

Initialize a variable and assign a value to the agent

    _netreachability = [[Networkreachability alloc] init];    _netreachability.delegate = self;

Implementation of the Agent

#pragma mark-networkreachability delegate-(void) reachable: (NetworkStatus) netstatus {    switch (netstatus) {        Case notreachable:            NSLog (@ "No network!");            break;        Case Reachableviawifi:            NSLog (@ "WiFi");            break;        Case Reachableviawwan:            NSLog (@ "3G");            break;        Default: Break            ;    }}

Of course, don't forget the proxy statement:

<NetworkReachabilityDelegate>



over!



IOS Monitoring Network changes

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.