IOS monitoring network changes

Source: Internet
Author: User

IOS monitoring network changes

With the upgrade of Mobile Networks: 2G-> 3G-> 4G, or even 5G under development, the network speed is getting faster and faster, but the traffic is also like a flow of water.

The Internet does not spread a story: if you forget to turn off traffic during sleep, the house will be moved the next day!

This is an exaggerated statement, but as an excellent App developer, we need to give the most appropriate prompt in the App.

When a large amount of traffic is required (for example, video or download), some tips are given.

During the user's video period, the user will prompt whether to continue watching the video when switching the network!

The following describes how to monitor network status changes in real time!

I am using the most widely used network monitoring class: Reachability

Click here to download this Demo: Click to download

Decompress the downloaded file in the upper part and add the NetworkReachability folder to the project you want to add.

Example Description: This example is used to demonstrate how to use the systempolicatio Reachalility program interface to determine the related network connection status and status change. Therefore, the Reachability in this example is used. the premise of the (h/m) file in your own project is that SystemConfiguration must be introduced. framework.


Import header files:

#import "NetworkReachability.h"

Define global variables

NetworkReachability *_netReachability;

Initialize variables and assign values to proxies

    _netReachability = [[NetworkReachability alloc] init];    _netReachability.delegate = self;

Proxy implementation

#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:

 



OVER!



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.