title: iPhone app crashes while checking internet connectivity
body: <p>In my iPhone app, I need to detect the internet Connection availability.</p>
  
  <p>So I am referencing some files from "Reachability" project of Apple.</p>
  
  <p>Link is given below:</p>
  
  <p><a href="http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html" rel="nofollow">http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html</a></p>
  
  <p>I create a new project and implement the code below in viewWillAppear but the app crashes.</p>
  
  <p>I included the Reachability.h, Reachability.m from Apple's demo project.</p>
  
  <p>I also included SystemConfiguration Framework.</p>
  
  <p>app works fine when Internet is Working. But app Crashes when Internet in not Working.</p>
  
  <p>Even I checked the console but there is no notification or error shown in the console.</p>
  
  <pre><code>   Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
  
  NetworkStatus internetStatus = [r currentReachabilityStatus];
  if ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN))
  {
      UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Internet Connection" message:@"Available" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
      [myAlert show];
      [myAlert release];
      }
  else
  {
      UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
      [myAlert show];
      [myAlert release];
      }
  </code></pre>
  
  <p>What could be the reason for crash?</p>
  
  <p>What should I do?</p>
  
  <p>Thanks!!</p>