iPhone 网络检测是否可用 代码简单实现是本文要介绍的内容,基本是基于代码实现结果,我们来看内容,
在IPhone开发中,对于需要联网的应用,可以用如下代码检测网络是否可用。 Reachability可以在开发帮助中搜索“ Reachability”得到。
- - (void) reachabilityChanged: (NSNotification* )note
- {
- Reachability* curReach = [note object];
- NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
- if(NotReachable == [curReach currentReachabilityStatus])
- {
- // can be changed to Alert here.
- DEBUG_OUTPUT(@"%@",@"Network not available!");
- }
- }
- - (void)applicationDidFinishLaunching:(UIApplication *)application
- {
- [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:)
- name: kReachabilityChangedNotification object: nil];
- internetReach = [[Reachability reachabilityForInternetConnection] retain];
- [internetReach startNotifer];
- [window addSubview:navigationController.view];
- [window makeKeyAndVisible];
- }
小结:iPhone 网络检测是否可用 基于代码实现的内容介绍完了,希望本文对你有所帮助!
本文来自:http://www.cnblogs.com/MobileDevelop/archive/2010/07/17/1779774.html
【编辑推荐】