iOS中 WGAFN_网络监控 技术分享

需要用到第三方AFNetworking/SVProgressHUD

没有的可以关注我微博私信我.http://weibo.com/hanjunqiang

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(@"没有网络(断网)");
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"手机自带网络");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");

                [SVProgressHUD showSuccessWithStatus:@"WIFI"];

                break;
        }

    }];

    // 3. 开始监控
    [manager startMonitoring];

    return YES;
}

最终效果:

iOS中 WGAFN_网络监控 技术分享

上一篇:C 结构体位域


下一篇:mybatis配置文件xxxx.xml中缺失返回类型的后果A query was run and no Result Maps were found