IOS代碼筆記之網(wǎng)絡(luò)嗅探功能
更新時間:2016年07月06日 10:21:30 作者:情深雨蒙
這篇文章主要為大家詳細(xì)介紹了IOS網(wǎng)絡(luò)嗅探功能實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了IOS網(wǎng)絡(luò)嗅探工具,供大家參考,具體內(nèi)容如下
一、效果圖
二、工程圖
三、代碼
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; //啟動網(wǎng)絡(luò)嗅探功能 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 -網(wǎng)絡(luò)嗅探 - (void)ReachabilitySniffNotification:(NSNotification* )notification { Reachability* curReach = [notification 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:@"您正在使用WiFi網(wǎng)絡(luò)" message:Nil delegate:self cancelButtonTitle:Nil otherButtonTitles:@"本次不再提醒",@"知道了", nil]; [alert show]; break; } case ReachableViaWWAN: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"您正在使用移動網(wǎng)絡(luò),運(yùn)營商會收取流量費(fèi),建議使用WiFi網(wǎng)絡(luò)" message:Nil delegate:self cancelButtonTitle:Nil otherButtonTitles:@"本次不再提醒",@"知道了", nil]; [alert show]; break; } case NotReachable: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"沒有網(wǎng)絡(luò)" message:Nil delegate:self cancelButtonTitle:Nil otherButtonTitles:@"本次不再提醒",@"知道了", nil]; [alert show]; break; } } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
iOS自定義collectionView實現(xiàn)毛玻璃效果
不知道大家發(fā)現(xiàn)沒有蘋果在iOS7.0之后,很多系統(tǒng)界面都使用了毛玻璃效果,增加了界面的美觀性,所以這篇文章跟大家分享個iOS自定義collectionView實現(xiàn)毛玻璃效果的方法,有需要的可以參考借鑒,下面來一起看看。2016-09-09iOS中利用CAGradientLayer繪制漸變色的方法實例
有時候iOS開發(fā)中需要使用到漸變色,來給圖片或者view蓋上一層,使其顯示效果更好,所以這篇文章主要給大家介紹了關(guān)于iOS中利用CAGradientLayer繪制漸變色的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。2017-11-11iOS開發(fā)網(wǎng)絡(luò)篇—實現(xiàn)大文件的多線程斷點(diǎn)下載
iOS開發(fā)中經(jīng)常會用到文件的下載功能,這篇文章主要介紹了iOS開發(fā)網(wǎng)絡(luò)篇—實現(xiàn)大文件的多線程斷點(diǎn)下載,今天咱們來分享一下思路。2016-11-11在iOS中使用OpenGL ES實現(xiàn)繪畫板的方法
這篇文章主要介紹了在iOS中使用OpenGL ES實現(xiàn)繪畫板的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03