检测网络状态的方法
来源:互联网 发布:外文数据库下载 编辑:程序博客网 时间:2024/04/30 06:22
#import<UIKit/UIKit.h>
#import"Reachability.h" (需要到导入第三Reachability库)
@classViewController;
@classAppDelegate;
@protocol AppDelegateDelegate <NSObject>
- (void)update:(AppDelegate*)appDelegate;
@end
@interface AppDelegate :UIResponder <UIApplicationDelegate>
@property (strong,nonatomic) UIWindow *window;
@property (assign,nonatomic) NetworkStatus netstatus;
@property (assign,nonatomic) BOOL isConnected;
@property (retain,nonatomic) Reachability *hostReach;
@property (assign,nonatomic) id<AppDelegateDelegate>delegate;
@end
#import"AppDelegate.h"
#import"ViewController.h"
@implementation AppDelegate
- (void)dealloc
{
[_windowrelease];
[_hostReachrelease];
[superdealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_isConnected = NO;
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(ReachabilityChanged:)name:kReachabilityChangedNotificationobject:nil];
self.hostReach = [ReachabilityreachabilityWithHostName:@"www.baidu.com"];
[_hostReachstartNotifier];
self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]]autorelease];
// Override point for customization after application launch.
ViewController *viewController = [[ViewControlleralloc] init];
UINavigationController *navigationController = [[UINavigationControlleralloc]initWithRootViewController:viewController];
[viewController release];
self.window.rootViewController = navigationController;
[navigationControllerrelease];
[self.windowmakeKeyAndVisible];
return YES;
}
//网络监听事件
- (void)ReachabilityChanged:(NSNotification*)notice
{
NSString *connectionKind = nil;
Reachability *curReach = [notice object];
NSParameterAssert([curReachisKindOfClass:[Reachabilityclass]]);
_netstatus = [curReach currentReachabilityStatus];
switch (_netstatus) {
case NotReachable:
connectionKind =@"当前没有网络连接\n请查看你的网络设置";
_isConnected = NO;
break;
case ReachableViaWiFi:
connectionKind =@"当前使用的网络是WIFi";
_isConnected = YES;
break;
case ReachableViaWWAN:
connectionKind =@"当前使用的网络是WWAN";
_isConnected = YES ;
break;
default:
break;
}
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提醒"message:connectionKind delegate:selfcancelButtonTitle:@"OK"otherButtonTitles: nil];
[alert show];
[alert release];
if (_delegate && [_delegaterespondsToSelector:@selector(update:)]) {
[_delegateperformSelector:@selector(update:)withObject:self];
}
}
@end
- 检测网络状态的方法
- 网络连接状态检测的一个方法
- Android,检测网络状态的方法
- 网络状态检测方法分析
- 网络状态检测方法分析
- 网络状态检测方法分析
- 检测本地网络连接状态断开以及恢复的方法
- iOS两种检测网络状态的方法
- iOS 检测网络状态的2个方法
- 检测用户的网络状态
- 检测网络状态的方式
- ios网络状态的检测
- 网络状态检测方法测试结果
- 如何去检测网络的连接状态
- C#检测网络的连接状态
- C#检测网络的连接状态
- Android检测网络状态的广播
- 广播检测网络状态的改变
- 为什么要用工厂模式
- 鼠标点在文本框上文本框成密码框,如果不输入,鼠标离开,又变成文本框,文本框内显示”请输入密码“(本内容来自唯才教育网http://www.hn1c.com 原文地址:http://hao.cspeng
- HDOJ 1211 RSA
- android 起动APP时锁住(Lock apps)
- centos6.4关闭nvidia显卡驱动
- 检测网络状态的方法
- Opencv中cvCopy()和cvCloneImage()的区别
- vim编辑器使用手册
- DM8261芯片检测修改程序QCTool_1.0.0.3_110622
- C语言中的label
- Firefox火狐下载插件
- HDOJ 2034 人见人爱A-B
- 数据库三范式
- 利用jni调用c的dll