Search code examples
iosobjective-ciphoneipv6

Supporting IPv6 on iOS App (Keep getting rejected although it works in tests)


I am trying for quite some time to deploy an app but it keeps getting rejected as it doesn't work on Apple's IPv6 only network, even though I am using NSURLSession to send a POST. I have made more attempts than I can count and ran out of options, does anyone know if it is a problem related to their testing environment or it is to my code? Here it is the code:

    - (NSData *) postToServer: (NSData *) msg {

        __block NSData *urlData = NULL;
        self.status = @"offline";
        dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];

        NSURL *url = [NSURL URLWithString:@"http://myserver.php"];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:msg];

        NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

            if (error) {
                self.status = @"offline";
                dispatch_semaphore_signal(semaphore);
                return;
            }

            if ([response isKindOfClass:[NSHTTPURLResponse class]]) {

                NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];

                if (statusCode >= 200 && statusCode < 300) {

                    self.status = @"online";
                    urlData = data;

                }
                else {

                    self.status = @"offline";

                }
                NSLog(@"Código resposta: %ld / Resposta ==> %@", (long)statusCode, [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]);
            }
            dispatch_semaphore_signal(semaphore);

        }];
        [postDataTask resume];

        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);

        return urlData;

    }

Please, if I have made anything wrong on this help me fix it, this is delaying my work schedule so much and I could not figure it out even reading all Apple forum's threads about IPv6. (This code works at my workplace for iPhone SE iOS 9.3.2, only fails at the review).
Thanks for the help.
Natan


Solution

  • As stated by OP for his solution:

    The problem was my server, which was not ready entirely ready for IPv6. If it had no IPv6 address, the app could synthetize an IPv4 addr while on IPv6 only network and communicate normally, but my host had the address but could not respond through it. If anyone else is having issues with this, try using this test: http://ipv6-test.com/validate.php and check if your host passes AAAA DNS record, but fails the rest, that being the case you should take a look at your server first, not the code (assuming your code is all right, NSURLSession and stuff.