APPDelegate.m里
- (void)ifNet // 此方法在Launching里直接调用[self ifNet]
{
// 检测是否有网络
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
{
__sheetWindow = [WKAlertView showAlertViewWithStyle:WKAlertViewStyleFail title:@"警告" detail:@"当前无网络连接" canleButtonTitle:nil okButtonTitle:@"重新连接" callBlock:^(MyWindowClick buttonIndex) {
if (buttonIndex == 0) {
AFNetworkReachabilityManager *reachManager = [AFNetworkReachabilityManager sharedManager];
if (reachManager.reachable) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"Internet" object:nil];
//Window隐藏,并置为nil,释放内存 不能少
__sheetWindow.hidden = YES;
__sheetWindow = nil;
}else
{
__sheetWindow.hidden = YES;
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(sheetWindowAppear:) userInfo:nil repeats:NO];
}
}
}];
}
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
// NSLog(@"使用的wifi连接");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
// NSLog(@"使用3G网络");
break;
default:
break;
}
}];
}
AFN是对NSURL的封装
ASI是对 CFN的封装(2012.10暂停)
所以,ASI和NSURL平级
AFNetworking框架使用浅析:
http://wenku.baidu.com/link?url=F_N0DF4zG6r8NP9KMRv7WQOMeXN9hp7L4OAWf2KGyx7h7yxrUoJaC_ITtXoG7fiDnWM78v28_AIqBrbvAtHrbYXGtTaw1-IzGQoHKIz8R0O
iOS网络检测与提示实现

本文介绍了一个iOS应用中实现网络状态检测的方法,并通过AFNetworking框架进行网络可达性监测,根据不同网络状态显示相应的提示信息。
1万+

被折叠的 条评论
为什么被折叠?



