使用公共dns服务器的CFHostStartInfo解决方案的iOS替代方案?

使用公共dns服务器的CFHostStartInfo解决方案的iOS替代方案?,ios,dns,Ios,Dns,我的申请在大多数情况下似乎都很有效 然而,当它在中国运行时,它有时无法向我提供服务器的IP地址。我使用它异步获取IP地址: //... CFStringRef hostAddress = CFStringCreateWithCString( kCFAllocatorDefault, hostAddressStr, kCFStringEncodingASCII ); CFHostRef theHostRef = CFHostCreateWithName( kCFAllocatorDefault,

我的申请在大多数情况下似乎都很有效

然而,当它在中国运行时,它有时无法向我提供服务器的IP地址。我使用它异步获取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;
                }
            }
         }
     }
     // ...
}
/。。。
CFStringRef hostAddress=CFStringCreateWithCString(kCFAllocatorDefault、hostAddressStr、kCFStringEncodingASCII);
CFHostRef theHostRef=CFHostCreateWithName(kCFAllocatorDefault,主机地址);
CFRelease(主机地址);
CFHostClientContext;
context.version=0;
context.retain=nil;
context.release=nil;
context.copyDescription=nil;
context.info=self;
Boolean set_ok=CFHostSetClient(hostref、myCFHostClientCallBack和context);
CFStreamError cfError;
CFHostScheduleWithRunLoop(hostRef、CFRunLoopGetCurrent()、kCFRunLoopCommonModes);
布尔值is_resolving=CFHostStartInfoResolution(hostref、kcfhostaddress和cfError);
//...
void myCFHostClientCallBack(CFHostRef theHost,CFHostInfoType typeInfo,const CFStreamError*错误,void*信息){
int count=CFArrayGetCount(arrayRef);
对于(int index=0;indexsin\u addr);
if(addressString!=NULL){
if(resolvedAddressString==NULL){
resolvedAddressString=地址字符串;
}
}
}
}
// ...
}
我怀疑iOS使用任何本地可用的DNS来执行域名到ip地址的查找,但我强烈怀疑DNS有时会因为某种原因而失败

如果ISP提供的dns服务器无法返回我们服务器的IP地址,是否有一种简单的方法可以使用公共dns服务器(如谷歌)进行类似的查询?
我还没有找到用于此目的的API,因此如果可能,我希望有一些指向一些简单示例代码的链接来实现此目的。

问题:查找是否异步执行?如果没有,你会怎么做?我猜运行循环的某些地方……是的,查找是异步的,在运行循环中安排。