在iPhone 5S WiFi中检测到3G和我的iPhone 4是正常的。 两者都在iOS 7.1中。
在某些设备中它也会发生。
WiFi禁用且已连接3G,我仔细检查以确定互联网连接是否正常,确实设备本身没问题。
知道为什么吗?
修改1:
以下代码:
- (void)registerReachabilityNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(checkNetworkStatus:)
name:kReachabilityChangedNotification object:nil];
Reachability *reach = [Reachability reachabilityForInternetConnection];
[reach startNotifier];
NSNotification *note = [[NSNotification alloc] initWithName:kReachabilityChangedNotification object:reach userInfo:nil];
[self checkNetworkStatus:note];
}
- (void)checkNetworkStatus:(NSNotification*)notification
{
Reachability *reach = notification.object;
NSParameterAssert([reach isKindOfClass: [Reachability class]]);
NetworkStatus internetStatus = [reach currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(@"No internet connection.");
break;
}
case ReachableViaWiFi:
{
NSLog(@"The internet is working via WIFI.");
break;
}
case ReachableViaWWAN:
{
NSLog(@"The internet is working via WWAN.");
break;
}
}
}
修改1:
此代码:
NetworkStatus nStats = [[Reachability reachabilityForLocalWiFi] currentReachabilityStatus];
if (nStats != ReachableViaWiFi) {
NSLog(@"nStats != ReachableViaWiFi");
}
if (nStats == ReachableViaWiFi) {
NSLog(@"WIFI");
}
else if (nStats == ReachableViaWWAN) {
NSLog(@"WWAN");
}
else if (nStats == NotReachable) {
NSLog(@"not reachable");
}
else {
NSLog(@"undetermined reachability.");
}
给我这个:
Reachability Flag Status: WR t------ localWiFiStatusForFlags
nStats != ReachableViaWiFi
not reachable
答案 0 :(得分:4)
我的方法完全错误,正确的方法代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"CONNECTION: %@", NSStringFromNetworkStatus([MobileControlHandler checkConnection]));
return YES;
}
+ (NetworkStatus)checkConnection
{
NetworkStatus wifiStatus = [[Reachability reachabilityForLocalWiFi] currentReachabilityStatus];
NetworkStatus internetStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
if (wifiStatus == ReachableViaWiFi) {
return ReachableViaWiFi;
}
else if (wifiStatus != ReachableViaWiFi && internetStatus == ReachableViaWWAN) {
return ReachableViaWWAN;
}
else {
return NotReachable;
}
}
FOUNDATION_EXPORT NSString *NSStringFromNetworkStatus(NetworkStatus netStatus)
{
if (netStatus == ReachableViaWiFi) {
return @"ReachableViaWiFi";
} else if (netStatus == ReachableViaWWAN) {
return @"ReachableViaWWAN";
} else if (netStatus == NotReachable) {
return @"NotReachable";
} else {
return @"Undetermined reachbility flag";
}
}
简介:
Reachability Flag Status: WR t------ localWiFiStatusForFlags
Reachability Flag Status: WR t----l- networkStatusForFlags
CONNECTION: ReachableViaWWAN
答案 1 :(得分:4)
只需从Apple下载新的Reachability类 https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
它也适用于ios 8。
有关iOS应用开发的更多互动内容,Checkout https://appengineer.in/
答案 2 :(得分:0)
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
它是一个单身人士,所以你可以马上开始使用它。
例如:
{{1}}