Ios 如果不在主队列上,则无法使用CFHostStartInfoResolution解析DNS地址

Ios 如果不在主队列上,则无法使用CFHostStartInfoResolution解析DNS地址,ios,core-foundation,Ios,Core Foundation,我有一个使用SimplePing示例源代码的项目。它在大多数情况下工作得非常好,但我遇到过异步名称解析从未执行回调的情况 启动DNS查找(直接从SimplePing.m)的代码如下所示: CFHostClientContext context = {0, (__bridge void *)(self), NULL, NULL, NULL}; CFStreamError streamError; assert(self->_host == NULL);

我有一个使用SimplePing示例源代码的项目。它在大多数情况下工作得非常好,但我遇到过异步名称解析从未执行回调的情况

启动DNS查找(直接从SimplePing.m)的代码如下所示:

    CFHostClientContext context = {0, (__bridge void *)(self), NULL, NULL, NULL};
    CFStreamError       streamError;

    assert(self->_host == NULL);

    self->_host = CFHostCreateWithName(NULL, (__bridge CFStringRef) self.hostName);
    assert(self->_host != NULL);

    CFHostSetClient(self->_host, HostResolveCallback, &context);

    CFHostScheduleWithRunLoop(self->_host, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

    NSLog(@">CFHostStartInfoResolution");
    success = CFHostStartInfoResolution(self->_host, kCFHostAddresses, &streamError);
    NSLog(@"<CFHostStartInfoResolution");
CFHostClientContext={0,(u桥空*)(self),NULL,NULL,NULL};
CFStreamError拖缆错误;
断言(self->_host==NULL);
self->_host=CFHostCreateWithName(NULL,(u桥CFStringRef)self.hostName);
断言(self->_host!=NULL);
CFHostSetClient(自->\u主机、HostResolveCallback和上下文);
CFHostScheduleWithRunLoop(自->\u主机,CFRunLoopGetCurrent(),kCFRunLoopDefaultMode);
NSLog(@“>CFHostStartInfoResolution”);
success=cfhoststartinforefolution(self->\u主机、kcfhostaddress和streamError);

NSLog(@"如果该方法在另一个runloop上运行,您应该确保在DNS完成时runloop仍在运行或在KCFRunlopDefaultMode上运行。问题是DNS从未完成,因为runloop似乎停止运行。至少我认为是这样的。我真的不明白是什么原因导致runloop停止运行。我有一个类似的情况,我的问题是UIViewController上有一个局部变量,而不是一个属性。该变量发布得太早,代码从未通过上面显示的第二个NSLog。