Objective c 从wifi切换到3g时网络连接丢失
我遇到了一个奇怪的问题,从wifi切换到3g后,可达性和NSURLConnection显示错误(没有互联网连接/网络连接丢失)。虽然所有的应用程序在切换到3g后都运行良好。 我会仔细检查应用程序和设备的移动数据是否打开。重新安装应用程序它工作正常,请帮助。 以下是一些可达性代码:Objective c 从wifi切换到3g时网络连接丢失,objective-c,iphone,xcode6,ios10.3.2,Objective C,Iphone,Xcode6,Ios10.3.2,我遇到了一个奇怪的问题,从wifi切换到3g后,可达性和NSURLConnection显示错误(没有互联网连接/网络连接丢失)。虽然所有的应用程序在切换到3g后都运行良好。 我会仔细检查应用程序和设备的移动数据是否打开。重新安装应用程序它工作正常,请帮助。 以下是一些可达性代码: -(BOOL)toCheckNetworkStatus { internetReachable = [Reachability reachabilityForInternetConnection]; [internet
-(BOOL)toCheckNetworkStatus
{
internetReachable = [Reachability reachabilityForInternetConnection];
[internetReachable startNotifier];
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
if(internetStatus == NotReachable ){
[self displayToastWithMessage:@"Connection lost!" AndSubtitle:@"Please check your network connection." delay:3.2];
return NO;
}
else{
return YES;
}
}
NSURLConnection的代码:
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:dictionary
options:0
error:&error];
if (error)
NSLog(@"Failure to serialize JSON object %@", error);
NSURL *url = [NSURL URLWithString:palURL];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:TIMEOUTINTERVAL];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPBody:postData];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:
^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if (data)
{
NSMutableDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"UPLOADED LOCATION RESPONSE = %@",responseDict);
}
else
{
NSLog(@"connectionError===%@",connectionError);
}
}];