#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; self.window.rootViewController = [[RootViewController alloc] init]; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end
/**
* 注意: 要在工程里导入SystemConfiguration.framework框架
* Reachability下载地址: https://github.com/tonymillion/Reachability
*/
#import "RootViewController.h"
#import "Reachability.h"
@interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad {
[super viewDidLoad]; Reachability *reach = [Reachability reachabilityWithHostname:@"www.baidu.com"]; NSLog(@"------%@",reach.currentReachabilityString); UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:reach.currentReachabilityString message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; reach.reachableBlock = ^(Reachability *reach){
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"网络可用");
alertView.message = @"当前网络可用";
[alertView show];
});
}; reach.unreachableBlock = ^(Reachability *reach){
alertView.message = @"当前网络不可用";
[alertView show];
};
[reach startNotifier]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

iOS Reachability的基本用法的更多相关文章

  1. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  2. ios多线程-GCD基本用法

    ios中多线程有三种,NSTread, NSOperation,GCD 这篇就讲讲GCD的基本用法 平时比较多使用和看到的是: dispatch_async(dispatch_get_global_q ...

  3. iOS中block的用法 以及和函数用法的区别

    ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候  MyBlock(); 带参数的 ...

  4. iOS UIProgressView控件用法

    IOS中进度条控件的用法总结. 进度条控件是IOS开发中一个简单的系统控件,使用总结如下: 初始化一个进度条: - (instancetype)initWithProgressViewStyle:(U ...

  5. iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)

    1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...

  6. iOS block-base 动画简单用法+关键帧动画设置线性变化速度的问题

    本文转载至 http://www.tuicool.com/articles/aANBF3m 时间 2014-12-07 20:13:37  segmentfault-博客原文  http://segm ...

  7. ios中图片拉伸用法

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...

  8. iOS中的CocoaPods用法及常用命令

     CocoaPods是什么? ***CocoaPods的使用场景:*** 1. 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用 ...

  9. iOS多线程 GCD常见用法

    Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. dispatch queue分成以下三种: 1)运行在主线程的Main queue,通过dispat ...

随机推荐

  1. 移动Web应用开发入门指南——交互篇

    交互篇 从PC到移动端,视觉和交互是用户能直接感受到的差异.在视觉篇中已经提到,移动设备的物理属性一部分影响到视觉,另外一些部分将影响到交互.那么,移动设备影响交互的物理属性都有哪些变化呢?对于这个问 ...

  2. [ZZ] RGBM and RGBE encoding for HDR

    Deferred lighting separate lighting rendering and make lighting a completely image-space technique. ...

  3. PHP文件操作 之往一个文件写入数据

    //打开一个文件 $f = fopen($filename,'wb'); $filename:打开一个文件,不存在则自动创建,如果不能创建,说明指定的文件目录有错误 wb:写入的方式 ---- 覆盖原 ...

  4. nginx服务器安装与启动

    nginx服务器介绍 1.nginx服务器功能 nginx服务器可以扮演:轻量级的web服务器.应用服务器.代理服务器.反向代理服务器.后台服务器.CDN缓存服务器 nginx的基本模块: 内核模块C ...

  5. ATT 汇编语法

      在研华的pc104上使用看门狗要使用汇编.使用汇编来修改CMOS里面的参数.也就是内联汇编.linux下gcc只支持ATT汇编.所以这儿有必要将ATT语法学习学习.以后需要的时候翻出来温习温习. ...

  6. PureBasic 读取文件中一行的两个数据例子

    , "Test1.txt") ; if the file could be read, we continue... , "Test2.txt") ) = ; ...

  7. 二进制流 最后一段数据是最后一次读取的byte数组没填满造成的

    while(in.read(temp)!=-1){ out.write(temp); } 改成: int len; while((len=in.read(temp))!=-1){out.write(t ...

  8. C 判断路径存在

    1   用   int   access(const   char   *pathname,   int   mode);   判断有没有此文件或目录 --它区别不出这是文件还是目录2   用   i ...

  9. 【转】Unity LayerMask 的位运算

    Unity的Layer Unity是用 int32来表示32个Layer层,int32用二进制来表示一共有32位. 0000 0000 0000 0000 0000 0000 0000 0000 31 ...

  10. c语言作业