简体   繁体   中英

App rejected NSUrlConnection IPv6 network issue iOS

iTunes App rejected.

Reason :

We discovered one or more bugs in your app when reviewed on iPhone running iOS 9.3.4 on Wi-Fi connected to an IPv6 network.

Specifically, the app content failed to load.

We tested it in NAT64 network (setup from mac) and it's working fine , but Apple review team have an issue with IPv6 network.

We have used NSURLConnection for calling web service , but getting nil response.

NSURLConnection:connectionDidFinishLoading: is called but getting nil NSData response in IPv6 network , it's working fine in IPv4 network

json parsing code

NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:receivedData options:kNilOptions | NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:&error];

getting parsing error becauseof nil receivedData : The data couldn't be read because it isn't in the correct format

it's all working fine in IPv4 network , also in IPv6 connectionDidFinishLoading: called but why getting nil response ?

Change your app NSURLSession. Use this delegate method to get the response

service url = "you parse your url here";

 NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
    NSURL * url = [NSURL URLWithString:serviceurl];
    NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
    NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithRequest:urlRequest];
    [dataTask resume];

In this delegate method you just copy and paste your connectionDidFinishLoading , connectionDidReceiveResponse , connectionDidReceiveData , connectionDidFailWithError should be in else part of (NSURLSession *)session task:

- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
    didReceiveResponse:(NSURLResponse *)response
     completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler
    {
        NSLog(@"### handler 1");
        [self.responseData setLength:0];
        completionHandler(NSURLSessionResponseAllow);
    }

    - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
        didReceiveData:(NSData *)data
    {


    }
    - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
    didCompleteWithError:(NSError *)error
    {
        if(error == nil)
        {

            NSLog(@"Download is Succesfull");
        }
        else
        {
            NSLog(@"Error %@",[error userInfo]);

        }
    }

I think this is helpful to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM