iPhone 網(wǎng)絡(luò)檢測是否可用 基于代碼實現(xiàn)
iPhone 網(wǎng)絡(luò)檢測是否可用 代碼簡單實現(xiàn)是本文要介紹的內(nèi)容,基本是基于代碼實現(xiàn)結(jié)果,我們來看內(nèi)容,
在IPhone開發(fā)中,對于需要聯(lián)網(wǎng)的應用,可以用如下代碼檢測網(wǎng)絡(luò)是否可用。 Reachability可以在開發(fā)幫助中搜索“ 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];
- }
小結(jié):iPhone 網(wǎng)絡(luò)檢測是否可用 基于代碼實現(xiàn)的內(nèi)容介紹完了,希望本文對你有所幫助!
本文來自:http://www.cnblogs.com/MobileDevelop/archive/2010/07/17/1779774.html
【編輯推薦】