This example for you to share the iOS network sniffer tools for your reference, the specific contents are as follows
One, the effect chart
Second, engineering drawing
Third, the 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 Didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window = [[UIWindow alloc]
Initwithframe:[[uiscreen Mainscreen] bounds]];
Override point for customization after application launch.
Rootviewcontroller *rootvc=[[rootviewcontroller Alloc]init];
Uinavigationcontroller *nav=[[uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:ROOTVC];
Self.window.rootviewcontroller=nav;
Start Network sniffing function Warningviawwan = TRUE; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (reachabilitysniffnotification:) Name:
Kreachabilitychangednotification Object:nil];
if (!reachability) {reachability = [reachability reachabilityforinternetconnection];
} [reachability Startnotifier];
[Self performselector: @selector (reachabilitysniff:) withobject:reachability afterdelay:20]; Self.window. backgroundcolor = [Uicolor Whitecolor];
[Self.window makekeyandvisible];
return YES; #pragma mark-Network sniffer-(void) Reachabilitysniffnotification: (nsnotification*) Notification {reachability* Curreach = [No
Tification Object];
[Self performselector: @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 WI
Fi network "Message:nil delegate:self cancelbuttontitle:nil otherbuttontitles:@" This time no longer remind, @ "Know", Nil];
[Alert show];
Break Case Reachableviawwan: {Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "You are using mobile network, operators will charge a traffic fee, suggest
Use WiFi network "Message:nil delegate:self cancelbuttontitle:nil otherbuttontitles:@" This time no longer remind, @ "Know", 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", @ "Know", Nil];
[Alert show];
Break
}
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.