在 iOS 应用程序上支持 IPv6(尽管在测试中有效,但不断被拒绝)
Supporting IPv6 on iOS App (Keep getting rejected although it works in tests)
我尝试了很长一段时间来部署一个应用程序,但它一直被拒绝,因为它不能在 Apple 的纯 IPv6 网络上运行,即使我正在使用 NSURLSession 发送 POST。我尝试的次数多得数不过来,运行 没有选择,有人知道这是与他们的测试环境有关还是与我的代码有关的问题?
这是代码:
- (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;
}
请,如果我在这方面做错了什么,请帮助我解决它,这大大耽误了我的工作日程,即使阅读了所有有关 IPv6 的 Apple 论坛主题,我也无法弄清楚。 (此代码在我的工作场所适用于 iPhone SE iOS 9.3.2,仅在审查时失败)。
感谢您的帮助。
纳坦
正如 OP 在其解决方案中所述:
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.
我尝试了很长一段时间来部署一个应用程序,但它一直被拒绝,因为它不能在 Apple 的纯 IPv6 网络上运行,即使我正在使用 NSURLSession 发送 POST。我尝试的次数多得数不过来,运行 没有选择,有人知道这是与他们的测试环境有关还是与我的代码有关的问题? 这是代码:
- (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;
}
请,如果我在这方面做错了什么,请帮助我解决它,这大大耽误了我的工作日程,即使阅读了所有有关 IPv6 的 Apple 论坛主题,我也无法弄清楚。 (此代码在我的工作场所适用于 iPhone SE iOS 9.3.2,仅在审查时失败)。
感谢您的帮助。
纳坦
正如 OP 在其解决方案中所述:
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.