关闭

网络监测

302人阅读 评论(0) 收藏 举报
分类:

#import "AFNetworkReachabilityManager.h"

typedef void (^NetworkReachable)(AFNetworkReachabilityManager * reachability);

typedef void (^NetworkUnreachable)(AFNetworkReachabilityManager


@property (nonatomic, copy) NetworkReachable    reachableBlock;

@property (nonatomic, copy) NetworkUnreachable  unreachableBlock;


 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkReachabilityDidChange:) name:AFNetworkingReachabilityDidChangeNotification object:nil];


- (void)networkReachabilityDidChange:(NSNotification *)aNotification

{

    BOOL Reachabled = [[AFNetworkReachabilityManager sharedManager] isReachable];

    if (Reachabled) {

        if (self.reachableBlock) { 

            self.reachableBlock(aNotification.object);

        }

    }else{

        if (self.unreachableBlock) {

            self.unreachableBlock (aNotification.object);

        }

    }

}


* reachability);

 @WeakObj(self);

    [[AFNetworkReachabilityManager sharedManager] startMonitoring];

    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {

        DLog(@"===================%ld", (long)status);

        @StrongObj(self);

        if ((long)status==1 ||(long)status==2)

        {

            [self loadData]; //加载数据

        }

    }];




0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:27972次
    • 积分:948
    • 等级:
    • 排名:千里之外
    • 原创:62篇
    • 转载:53篇
    • 译文:0篇
    • 评论:0条