#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. HDR the Bungie Way PPT and demo from MSFT

    Gamefest 2006 - HDR the Bungie Way Posted By: Falagard <falagard@hotmail.com> Date: 4/26/07 9: ...

  2. DS实验题 word

    题目: 代码: // // main.cpp // word // // Created by wasdns on 16/11/11. // Copyright © 2016年 wasdns. All ...

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

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

  4. 去除GHOST版系统自带的2345流氓软件

    话说2345真心流氓  用户想用你 自然不会删你 你这样强制性的 反而引起反感 应该是软件劫持性的捆绑 所以非常难起清除 最方便的方法就是 下载个 黄山IE修复专家   先把IE修复好 然后删除预安装 ...

  5. MySQL线程独享[转]

    一.前言在 MySQL 中,线程独享内存主要用于各客户端连接线程存储各种操作的独享数据,如线程栈信息,分组排序操作,数据读写缓冲,结果集暂存等等,而且大多数可以通过相关参数来控制内存的使用量。 二.线 ...

  6. Programming In hardware Programming in software

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION

  7. the essence of the internet idea

    Computer Systems A Programmer's Perspective Second Edition Of course, we are glossing over many diff ...

  8. 泌尿系统 Excretory system

    https://zh.wikipedia.org/wiki/泌尿系统 泌尿系統,有時也歸類於排泄系統(Excretory system)的一部分,負責尿液的產生.運送.儲存與排泄.人類的泌尿系統包括左 ...

  9. P1092 虫食算 NOIP2002

    为了测试stl 30分的暴力写法... #include <bits/stdc++.h> using namespace std; const int maxn = 11; int n; ...

  10. Qt和KDevelop在Linux下安装(qt-x11-commercial-src-4.3.1和kdevelop-3.5.0)

    qt-x11-commercial-src-4.3.1.tar.gz.kdevelop-3.5.0.tar.bz2在Fedora 8下安装. 安装KDevelop:安装KDevelop3.5要求,KD ...