English 中文(简体)
如何 2. 检查是否允许或未采用液压办法
原标题:How To check if wifi option enabled or not

如何检查在Peit(而不是Pebe)上是否允许使用“wifi”方案(但可能与“wifi”网之一无关)。

最佳回答

为此,你需要在其项目中开设可达到的班级。

之后:

#import "Reachability.h"

页: 1

- (void)viewDidLoad {
    Reachability *internetReach = [[Reachability reachabilityForInternetConnection] retain];
    [internetReach startNotifer];
    Reachability *wifiReach = [[Reachability reachabilityForLocalWiFi] retain];
    [wifiReach startNotifer];

    NetworkStatus netStatus1 = [internetReach currentReachabilityStatus];
    NetworkStatus netStatus2 = [wifiReach currentReachabilityStatus];
    if(netStatus1 == NotReachable && netStatus2 == NotReachable)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"This feature requires an internet connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }
    else
    {//wifi connection available;
}
}
问题回答

Found a great line of code for this. Add the Reachability class to your project and then you can do this:

BOOL isConnectedProperly = ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == ReachableViaWiFi);
  First import Reachability files into your project.

 -(void)loginButtonTouched
{  
  bool success = false;
  const char *host_name = [@"www.google.com" 
             cStringUsingEncoding:NSASCIIStringEncoding];

  SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName
                                                (NULL, host_name);
  SCNetworkReachabilityFlags flags;
  success = SCNetworkReachabilityGetFlags(reachability, &flags);
  bool isAvailable = success && (flags & kSCNetworkFlagsReachable) && 
                   !(flags & kSCNetworkFlagsConnectionRequired);

  if (isAvailable) 
  {
      NSLog(@"Host is reachable: %d", flags);
      // Perform Action if Wifi is reachable and Internet Connectivity is present
  }
  else
  {
      NSLog(@"Host is unreachable");
      // Perform Action if Wifi is reachable and Internet Connectivity is not present
  }       
}

When loginButtonTouched method is called we check that www.google.com is reachable or not. SCNetworkReachabilityFlags returns flags which helps us to understand the Status of internet connectivity. If isAvailable variable returns "true" then Host is Reachable means Wifi is reachable and Internet Connectivity is present.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签