[Code Note] network sniffing and code note sniffing

Source: Internet
Author: User

[Code Note] network sniffing and code note sniffing

I ,.

2. Engineering Drawing.

3. Code.

AppDelegate. h

#import <UIKit/UIKit.h>#import "Reachability.h"@interface AppDelegate : UIResponder <UIApplicationDelegate>{     Reachability *reachability;     BOOL WarningViaWWAN;}@property (strong, nonatomic) UIWindow *window;- (void)ReachabilitySniff:(Reachability*) curReach;- (void)ReachabilitySniffNotification:(NSNotification* )notification;- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;@end

 

AppDelegate. m

# Import "AppDelegate. h "# import" RootViewController. h "@ implementation AppDelegate-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; // Override point for customization after application launch. rootViewController * rootVC = [[RootViewController alloc] init]; UINavigat IonController * nav = [[UINavigationController alloc] initWithRootViewController: rootVC]; self. window. rootViewController = nav; // enable the network sniffing function WarningViaWWAN = TRUE; [[nsicationicationcenter defaultCenter] addObserver: self selector: @ selector (handler :) name: kReachabilityChangedNotification object: nil]; if (! Reachability) {reachability = [Reachability failed];} [reachability startNotifier]; [self defined mselector: @ selector (ReachabilitySniff :) withObject: reachability afterDelay: 20]; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES ;}# pragma mark-network sniffing-(void) ReachabilitySniffNotification :( NSNotification *) notification {Reachabilit Y * curReach = [notification object]; [self defined mselector: @ selector (ReachabilitySniff :) withObject: curReach afterDelay: 2];}-(void) ReachabilitySniff :( Reachability *) curReach {NSLog (@ "ReachabilitySniffNewWorkStatus"); if (! CurReach) {return;} NetworkStatus status = [curReach currentReachabilityStatus]; switch (status) {case ReachableViaWiFi: {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "you are using a Wi-Fi network" message: Nil delegate: self cancelButtonTitle: Nil otherButtonTitles: @ "no longer remind me this time", @ "OK", nil]; [alert show]; break;} case ReachableViaWWAN: {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "you are using a mobile network, and the carrier will charge the traffic fee. We recommend using a Wi-Fi network" message: nil delegate: self cancelButtonTitle: Nil otherButtonTitles: @ "this time no longer reminds me", @ "", nil]; [alert show]; break;} case NotReachable: {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "No network" message: Nil delegate: self cancelButtonTitle: Nil otherButtonTitles: @ "this time no longer reminds me ", @ "OK", nil]; [alert show]; break ;}}}

 

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.