iPhone 網絡檢測是否可用 基于代碼實現
作者:佚名
本文介紹的是iPhone 網絡檢測是否可用 基于代碼實現,內容不多,先來看實現過程。
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
【編輯推薦】
責任編輯:zhaolei
來源:
互聯網