使用公共DNS服务器的iOS替代CFHostStartInfoResolution?

我的应用程序似乎大多数时间工作正常。

但是,当它在中国运行时,它有时会给我我的服务器的IP地址。 我用这个来asynchronous获取IP地址:

//... CFStringRef hostAddress = CFStringCreateWithCString( kCFAllocatorDefault, hostAddressStr, kCFStringEncodingASCII ); CFHostRef theHostRef = CFHostCreateWithName( kCFAllocatorDefault, hostAddress ); CFRelease(hostAddress); CFHostClientContext context; context.version = 0; context.retain = nil; context.release = nil; context.copyDescription = nil; context.info = self; Boolean set_ok = CFHostSetClient( theHostRef, myCFHostClientCallBack, &context ); CFStreamError cfError; CFHostScheduleWithRunLoop( theHostRef, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); Boolean is_resolving = CFHostStartInfoResolution( theHostRef, kCFHostAddresses, &cfError ); //... void myCFHostClientCallBack( CFHostRef theHost, CFHostInfoType typeInfo, const CFStreamError *error, void* info) { int count = CFArrayGetCount(arrayRef); for( int index = 0; index < count; ++index ) { CFDataRef saData = (CFDataRef)CFArrayGetValueAtIndex(arrayRef, index); struct sockaddr_in* remoteAddr = (struct sockaddr_in*)CFDataGetBytePtr(saData); if( remoteAddr != NULL) { char* addressString = inet_ntoa(remoteAddr->sin_addr); if( addressString != NULL) { if( resolvedAddressString == NULL ) { resolvedAddressString = addressString; } } } } // ... } 

我怀疑iOS使用本地可用的DNS来执行域名到IP地址的查找,但是我有强烈的怀疑,因为某些原因,某些时候DNS失败了。

如果ISP提供DNS服务器无法返回我们的服务器的IP地址,是否有一个简单的方法可以使用公共DNS服务器,如谷歌进行类似的查询? 我还没有find一个这样的API,所以如果可能的话,我想有一些简单的示例代码的链接,以实现这一目标。