Reachability实时网络监听/AFNETWorking2.0+ 网络监听
来源:互联网 发布:网络公安报警 编辑:程序博客网 时间:2024/05/21 17:59
下载 官方 Reachability demo 导入Reachability.h .m 文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; //开启网络状况的监听 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; self.hostReach = [Reachability reachabilityWithHostName:@"www.baidu.com"] ; [self.hostReach startNotifier]; //开始监听,会启动一个run loop self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; return YES;}//网络链接改变时会调用的方法-(void)reachabilityChanged:(NSNotification *)note{ Reachability *currReach = [note object]; NSParameterAssert([currReach isKindOfClass:[Reachability class]]); //对连接改变做出响应处理动作 NetworkStatus status = [currReach currentReachabilityStatus]; //如果没有连接到网络就弹出提醒实况 self.isReachable = YES; if(status == NotReachable) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络连接异常" message:@"暂无法访问书城信息" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; [alert release]; self.isReachable = NO; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络连接信息" message:@"网络连接正常" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; [alert release]; self.isReachable = YES; }}
AFNETWorking2.0+ 网络监听
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(83, 154, 164);"></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">- (<span style="color: rgb(195, 34, 117);">BOOL</span>)application:(<span style="color: rgb(97, 34, 174);">UIApplication</span> *)application didFinishLaunchingWithOptions:(<span style="color: rgb(97, 34, 174);">NSDictionary</span> *)launchOptions</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">{</p><p></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(83, 154, 164);"><span style="color: rgb(0, 0, 0);"><span style="white-space: pre;"></span>[[</span><span style="color: rgb(97, 34, 174);">NSNotificationCenter</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(61, 29, 129);">defaultCenter</span><span style="color: rgb(0, 0, 0);">]</span><span style="color: rgb(61, 29, 129);">addObserver</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(195, 34, 117);">self</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(61, 29, 129);">selector</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(195, 34, 117);">@selector</span><span style="color: rgb(0, 0, 0);">(reachabilityChanged:)<span style="white-space: pre;"></span></span><span style="color: rgb(61, 29, 129);">name</span><span style="color: rgb(0, 0, 0);">:</span>AFNetworkingReachabilityDidChangeNotification<span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(61, 29, 129);">object</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(195, 34, 117);">nil</span><span style="color: rgb(0, 0, 0);">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;"> </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(60, 130, 140);"><span style="white-space: pre;"></span>AFNetworkReachabilityManager<span style="color: rgb(0, 0, 0);"> *manager = [</span>AFNetworkReachabilityManager<span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(41, 76, 80);">sharedManager</span><span style="color: rgb(0, 0, 0);">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;"> <span style="white-space: pre;"></span>;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;"> </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(60, 130, 140);"><span style="color: rgb(0, 0, 0);"><span style="white-space: pre;"></span>[</span>AFNetworkReachabilityManager<span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(41, 76, 80);">managerForDomain</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(201, 27, 19);">@"www.baidu.com"</span><span style="color: rgb(0, 0, 0);">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;"> </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(41, 76, 80);"><span style="color: rgb(0, 0, 0);"><span style="white-space: pre;"></span>[manager </span>startMonitoring<span style="color: rgb(0, 0, 0);">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(41, 76, 80);"><span style="color: rgb(0, 0, 0);"></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(41, 76, 80);"><span style="color: rgb(0, 0, 0);">}</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(41, 76, 80);"><span style="color: rgb(0, 0, 0);"></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(41, 76, 80);"></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">-(<span style="color: rgb(195, 34, 117);">void</span>)reachabilityChanged:(<span style="color: rgb(60, 130, 140);">AFNetworkReachabilityManager</span> *)note</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;"></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(60, 130, 140);"><span style="color: rgb(0, 0, 0);"> </span>AFNetworkReachabilityManager<span style="color: rgb(0, 0, 0);"> *manager = [</span>AFNetworkReachabilityManager<span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(41, 76, 80);">sharedManager</span><span style="color: rgb(0, 0, 0);">];</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;"> </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(49, 89, 93);"><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(195, 34, 117);">if</span><span style="color: rgb(0, 0, 0);"> (manager.</span><span style="color: rgb(83, 154, 164);">networkReachabilityStatus</span><span style="color: rgb(0, 0, 0);"> == </span>AFNetworkReachabilityStatusNotReachable<span style="color: rgb(0, 0, 0);">) {</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;"> <span style="color: rgb(97, 34, 174);">UIAlertView</span> *alert = [[<span style="color: rgb(97, 34, 174);">UIAlertView</span> <span style="color: rgb(61, 29, 129);">alloc</span>]<span style="color: rgb(61, 29, 129);">initWithTitle</span>:<span style="color: rgb(195, 34, 117);">nil</span> <span style="color: rgb(61, 29, 129);">message</span>:<span style="color: rgb(201, 27, 19);">@"</span><span style="font-family: 'Heiti SC Light'; color: rgb(201, 27, 19);">没有网络链接</span><span style="color: rgb(201, 27, 19);"> "</span> delegate:<span style="color: rgb(195, 34, 117);">nil</span><span style="color: rgb(61, 29, 129);">cancelButtonTitle</span>:<span style="color: rgb(201, 27, 19);">@"</span><span style="font-family: 'Heiti SC Light'; color: rgb(201, 27, 19);">我知道了</span><span style="color: rgb(201, 27, 19);">"</span> otherButtonTitles: <span style="color: rgb(195, 34, 117);">nil</span>];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;"> [alert <span style="color: rgb(61, 29, 129);">show</span>];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;"> }</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; min-height: 16px;"></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo;">}</p><p></p>
0 0
- Reachability实时网络监听/AFNETWorking2.0+ 网络监听
- Reachability实时网络监听/AFNETWorking2.0+ 网络监听
- 用Reachability实时监听网络的变化
- Reachability实时准确监听网络状态
- 监听网络变化Reachability
- Reachability网络监听
- 关于IOS网络实时监听中reachability文件的问题
- 网络:监听网络(使用Reachability框架)
- 网络实时监听
- IOS Reachability库监听网络状态
- iOS使用Reachability监听网络状态
- ios-通过Reachability监听网络状态
- http网络编程实例(利用 Reachability监听网络状态)
- ios实时监听网络状态
- Android实时监听网络状态
- Android 实时监听网络状态
- Android实时监听网络状态
- Android实时监听网络状态
- 右移 32 位怎么没变化?
- DM642 模拟SPI通信
- C# 静态构造函数和静态变量
- mysql5.6 too many connections问题解决及其他参数设置
- HDU 1535 Invitation Cards (POJ 1511)
- Reachability实时网络监听/AFNETWorking2.0+ 网络监听
- Next Permutation -- LeetCode(下一个字典序)
- .m、.fig等文件与MATLAB关联设置
- c#面试题总结
- 嵌入式课程设计实践(二)——串口
- C++ 播放音频流(PCM裸流)
- MySQL 重启方法
- sql的优化处理
- Intents and Intent Filters