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