首页 > 代码库 > Reachability 检测网络状态
Reachability 检测网络状态
-(void)viewWillAppear:(BOOL)animated
{
[IOSExcept JudgeNetwork];//联网
NSLog(@"检查网络 请稍后.....");
self.backImage.hidden = YES;//隐藏背景图片
if (IOS.isDayMode == 1)
{
[self.backImage setImage:[UIImage imageNamed:@"back_day"]];
}
else
{
[self.backImage setImage:[UIImage imageNamed:@"back_day"]];
}
}
-(void)viewDidAppear:(BOOL)animated
{
//===================================从Nib中加载 自定义标签栏======================================
[[NSBundle mainBundle] loadNibNamed:@"MainController" owner:self options:nil];
self.tabBarController.view.frame = CGRectMake(0, 20, 320, 460);
//检查网络 如果没有网络 将弹出提示
if (IOSExcept.netWork == 0)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"网络状态" message:@"没有网络连接" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil ];
[alert show];
[alert release];
}
else
{
//联网 就加载数据
//如果连到了网络 推荐接口 #define KDataRecommendlistUrl [NSURL URLWithString:@"http://iphonenew.ecartoon.net/book_list.php?type=4"]
self.recommendData = http://www.mamicode.com/[NSData dataWithContentsOfURL:KDataRecommendlistUrl];
//连载更新接口#define KDataSerializeUpdatelistUrl [NSURL URLWithString:@"http://iphonenew.ecartoon.net/book_list.php?type=3"]
self.serialData = http://www.mamicode.com/[NSMutableData dataWithContentsOfURL:KDataSerializeUpdatelistUrl];
[IOSExcept parseHotWordsXmlwithObjectHotsWordsArray];//热门词汇解析
self.welcomeActivity.hidden = YES;
[self enterMainController];//进入五大模块
}
}
//{
// Reachability *r = [Reachability reachabilityWithHostName:@"www.apple.com"];
//
// switch ([r currentReachabilityStatus]) {
// case NotReachable:
// NSLog(@"无网络");
// break;
// case ReachableViaWiFi:
// NSLog(@"wifi 网络");
// break;
// case ReachableViaWWAN:
// NSLog(@"wan网络");
// break;
// default:
// break;
// }
Reachability 检测网络状态