Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从wifi切换到3g时网络连接丢失_Objective C_Iphone_Xcode6_Ios10.3.2 - Fatal编程技术网

Objective c 从wifi切换到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

我遇到了一个奇怪的问题,从wifi切换到3g后,可达性和NSURLConnection显示错误(没有互联网连接/网络连接丢失)。虽然所有的应用程序在切换到3g后都运行良好。 我会仔细检查应用程序和设备的移动数据是否打开。重新安装应用程序它工作正常,请帮助。 以下是一些可达性代码:

-(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);
         }
     }];