#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. netbeans使用技巧总结+快捷键大全

      部分经常用的快捷键: 使用快捷键Alt+Enter显示修复错误的方法. 4.导航 a)Alt+Shift+O :转到类. b)Ctrl+Tab :在打开的源文件中进行切换. c)Alt+Right ...

  2. commandname+commandargument

    (一) CommandName:其实可以设置成一种动作,比如Select,Update,Delete,等操作.就是说CommandName是确定他到底引发的是哪一事件,如果CommandName的名字 ...

  3. 关于DWZ模板中全选的使用

    只在使用DWZ框架时有用 模板中 <input type="checkbox" name="rule_id[]" />选项1 <input t ...

  4. 10个不太为人所知的,但实用的PHP函数

    10个不太为人所知的,但实用的PHP函数 您的评价:       较差  收藏该经验     阅读目录 php_check_syntax highlight_string show_source ph ...

  5. 当多个工程互相引用时,若有serverlet工程,提示java.lang.NoClassDefFoundError错误

    serverlet工程和其他的工程引用有所不同,直接在buildpath中添加引用的工程会报NoClassDefFoundError错误错误, 需要在properties-depoyment asse ...

  6. 02/07/2106 @ 6:28am (UTC)

    <?php echo pow(2,32); 4294967296 http://www.unixtimestamp.com/index.php 4294967296 Is equivalent ...

  7. ifarm 子 父页面方法如何互调

    1.iframe子页面调用父页面js函数 子页面调用父页面函数只需要写上window.praent就可以了.比如调用a()函数,就写成: 代码如下: window.parent.a(); 子页面取父页 ...

  8. 回退(pop&present)到根页面(根控制器)的方法,很不错~

    http://blog.csdn.net/assholeu/article/details/45897035

  9. Android源码剖析之Framework层进阶版(Wms窗口管理)

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 上一篇我们主要讲了Ams,篇幅有限,本篇再讲讲Wms,即WindowManagerService,管 ...

  10. Android源码剖析之Framework层实战版(Ams管理Activity启动)

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 讲到实战,就不得不拿两个例子来说明,本篇想拿的是应用最广泛的两个:Ams和Wms,一个管理activ ...