title: Reachability Help - WiFi Detection
body: <p>I have imported Reachability into my application, and I have a couple of how-to questions for you all. Let me explain my application and other tools first. </p>
  
  <p>This application communicates with two things AT THE SAME TIME, an ad-hoc network, and the internet through 3G. Note: The ad-hoc network IS NOT connected to the internet. This works perfectly - it's already implemented and tests out wonderfully. </p>
  
  <p>With that being said, I want to implement Reachability to detect a two things. </p>
  
  <p>1) Is the user connected to a wifi ad-hoc network? (Even better, if possible, is to detect if it is connected to the wifi ad-hoc network with a prefix of WXYZ. For example, if there are two networks listed, one called Linksys and the other called WXYZ-Testing_Platform, it knows whether or not it is connected to WXYZ). </p>
  
  <p>2) Can the user connect to the internet through 3G (or 2G, etc) and access our server?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT TO INCLUDE ANSWER FOR FUTURE LOOKERS:</strong></p>
  
  <p><strong>For 1), my code looks like this:</strong></p>
  
  <pre><code>.h
  #import &lt;SystemConfiguration/CaptiveNetwork.h&gt; //for checking wifi network prefix
  
  .m
  - (BOOL) connectedToWifi
  {
  
      CFArrayRef myArray = CNCopySupportedInterfaces();
      // Get the dictionary containing the captive network infomation
      CFDictionaryRef captiveNtwrkDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
  
      NSLog(@"Information of the network we're connected to: %@", captiveNtwrkDict);
  
      NSDictionary *dict = (__bridge NSDictionary*) captiveNtwrkDict;
      NSString* ssid = [dict objectForKey:@"SSID"];
  
      if ([ssid rangeOfString:@"WXYZ"].location == NSNotFound || ssid == NULL)
      {
          return false;
      }
      else
      {
          return true;
      }
  }
  </code></pre>
  
  <p><strong>And for 2)</strong>, I imported Reachability and have it using this method whenever I go to connect to the server... NOTE:replace <a href="http://www.google.com" rel="nofollow">http://www.google.com</a> with the server information</p>
  
  <pre><code>-(void) checkIfCanReachServer
  {
  UIAlertView *errorView;
      Reachability *r = [Reachability reachabilityWithHostName:@"http://www.google.com"];
      NetworkStatus internetStatus = [r currentReachabilityStatus];
  
  
      if(internetStatus == NotReachable) {
          errorView = [[UIAlertView alloc] 
                       initWithTitle: @"Network Error" 
                       message: @"Cannot connect to the server." 
                       delegate: self 
                       cancelButtonTitle: @"OK" otherButtonTitles: nil];  
          [errorView show];
      }
  }
  </code></pre>