您的位置:首页 > 理论基础 > 计算机网络

Reachability实时检测网络连接状况

2013-03-08 11:19 369 查看
//Called by Reachability whenever status changes.
- (void)reachabilityChanged: (NSNotification* )note
{
Reachability* curReach = [note
object];
NSParameterAssert([curReach
isKindOfClass: [Reachability class]]);

if (curReach == internetReach) {
NetworkStatus netStatus = [curReach
currentReachabilityStatus];

switch (netStatus)
{
case NotReachable:
{
DDLogInfo(@"internet Reachability no internet");
}
break;

default:
{
DDLogInfo(@"internet Reachability has internet begin xmppStart");
[[[_xmppClient
xmppiKnowFramework] xmppReconnect]
manualStart];
}
break;
}
}
}

- (void)networkReachability {
// Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the
// method "reachabilityChanged" will be called.
[[NSNotificationCenter
defaultCenter] addObserver:
self
selector:
@selector(reachabilityChanged:)
name:
kReachabilityChangedNotification
object:
nil];

internetReach = [[Reachability
reachabilityForInternetConnection] retain];
[internetReach
startNotifier];
} http://blog.csdn.net/yuhuangc/article/details/7410452
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: