IOS开发中如何检测网络连接
2015-12-03 10:28
573 查看
1)将**SystemConfiguration**framework添加到项目中。
2)添加Reachability.h和**Reachability.m**githubhttps://github.com/tonymillion/Reachability
3)实现方法
实现方法
StackOverFlow
2)添加Reachability.h和**Reachability.m**githubhttps://github.com/tonymillion/Reachability
3)实现方法
#import "Reachability.h" // Add this to the interface in the .m file of your view controller @interface MyViewController () { Reachability *internetReachableFoo; } @end
实现方法
// Checks if we have an internet connection or not - (void)testInternetConnection { internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"]; // Internet is reachable internetReachableFoo.reachableBlock = ^(Reachability*reach) { // Update the UI on the main thread dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"Yayyy, we have the interwebs!"); }); }; // Internet is not reachable internetReachableFoo.unreachableBlock = ^(Reachability*reach) { // Update the UI on the main thread dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"Someone broke the internet :("); }); }; [internetReachableFoo startNotifier]; }
StackOverFlow
相关文章推荐
- 10021---Java+MySQL实现网络爬虫程序
- JAVA 进行https传输中文乱码解决
- [网络管理]全双工与半双工的区别
- 32、OSPF在帧中继中不同网络类型配置总结
- xCODE7.1进行网络访问的设置
- iOS开发-网络篇 文件的上传
- Android Volley完全解析(二),使用Volley加载网络图片
- 程序中使用ajax时,type为put,或者delete时在 IIS上没效果,发生HTTP Error 405.0 - Method Not Allowed
- "javax.servlet.http.HttpServlet"was not found on the java build path
- TCP,IP详解,卷一:协议学习笔记之第一章概述
- 介绍一篇关于session的好文章
- 【网络爬虫】数据采集——将html的数据分析保存到数据库
- window环境下的apache的https的配置
- 【网络爬虫】数据的采集——爬取土木在线网的数据
- iOS 网络与多线程--2.同步Get方式的网络请求(阻塞)
- Socket TCP粘包拆包
- BP神经网络拟合数据及调优
- Qt显示网络图片
- Qt技巧:QTextEdit显示网络图片
- TCP协议