版权声明:本文为博主原创文章,未经博主允许不得转载。
需要用到第三方afnetworking/svprogresshud
appdelegate.m
#import "afnetworking.h"
#import "svprogresshud.h"
代码实现比较简单:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {
// override point for customization after application launch.
[svprogresshud setdefaultmasktype:svprogresshudmasktypenone];
[svprogresshud setringthickness:8];
// 1. 获得网络监控的管理者
afnetworkreachabilitymanager *manager = [afnetworkreachabilitymanager sharedmanager];
// 2. 设置网络状态改变后的处理
[manager setreachabilitystatuschangeblock:^(afnetworkreachabilitystatus status) {
// 当网络状态改变了, 就会调用这个block
switch (status) {
case afnetworkreachabilitystatusunknown:
nslog(@"未知网络");
break;
case afnetworkreachabilitystatusnotreachable:
nslog(@"没有网络(断网)");
case afnetworkreachabilitystatusreachableviawwan:
nslog(@"手机自带网络");
case afnetworkreachabilitystatusreachableviawifi:
nslog(@"wifi");
[svprogresshud showsuccesswithstatus:@"wifi"];
}
}];
// 3. 开始监控
[manager startmonitoring];
return yes;
}
最终效果:

原文地址:http://blog.csdn.net/qq_31810357/article/details/49563167