我需要检查用户是否连接到wifi。如果用户连接到移动互联网,我想要一条警告信息,例如"为了获得最佳性能,你应该连接到wifi"我怎么能在Objective-C中做到这一点?
答案 0 :(得分:2)
- (void)checkForWIFIConnection
{
Reachability* wifiReach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
if (netStatus != ReachableViaWiFi)// ReachableViaWWAN == 3G, ReachableViaWiFi == WIFI
{
NSString *message = [[NSString alloc] initWithFormat:NSLocalizedString(@"InitialNoWifiMessage", nil)];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"InitialNoWifiTitle", nil)
message:message
delegate:self
cancelButtonTitle:NSLocalizedString(@"InitialNoWifiAccept", nil)
otherButtonTitles:nil];
[alertView show];
}
else
{
// connected to Wifi
}
}