码迷,mamicode.com
首页 > 其他好文 > 详细

Reachability(判断网络是否连接)

时间:2015-04-13 18:32:43      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

/*
* 在应用委托的方法didFinishLaunchingWithOptions中添加
*/

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
reachability = [[Reachability reachabilityWithHostName:@"www.baidu.com"] retain];
[reachability startNotifier];
........
return YES;

/**
*此函数通过判断联网方式,通知给用户
*/
- (void)reachabilityChanged:(NSNotification *)notification
{
Reachability *curReachability = [notification object];
NSParameterAssert([curReachability isKindOfClass:[Reachability class]]);
NetworkStatus curStatus = [curReachability currentReachabilityStatus];
if(curStatus == NotReachable) {
[DOIN_Util logFax:@"连接失败"];
}
}

Reachability(判断网络是否连接)

标签:

原文地址:http://www.cnblogs.com/chen124/p/4422707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!