Code-based implementation of iPhone network detection

Source: Internet
Author: User

IPhone NetworkChecking whether the code is available for simple implementation is the content to be introduced in this article, basically based on the Code implementation results. Let's look at the content,

InIPhoneDuring development, you can use the following code to check whether the Network is available for applications requiring Internet connection. You can search for "Reachability" in development help to obtain the Reachability.

 
 
  1. - (void) reachabilityChanged: (NSNotification* )note  
  2. {  
  3. Reachability* curReach = [note object];  
  4. NSParameterAssert([curReach isKindOfClass: [Reachability class]]);  
  5. if(NotReachable == [curReach currentReachabilityStatus])  
  6. {     
  7.                 // can be changed to Alert here.  
  8. DEBUG_OUTPUT(@"%@",@"Network not available!");  
  9. }  
  10. }  
  11.  
  12. - (void)applicationDidFinishLaunching:(UIApplication *)application   
  13. {      
  14. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) 
  15. name: kReachabilityChangedNotification object: nil];  
  16.     internetReach = [[Reachability reachabilityForInternetConnection] retain];  
  17. [internetReach startNotifer];  
  18. [window addSubview:navigationController.view];  
  19.        [window makeKeyAndVisible];  

Summary:IPhone NetworkCheck whether code-based implementation is available. I hope this article will help you!

From: http://www.cnblogs.com/MobileDevelop/archive/2010/07/17/1779774.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.