CFStreamCreatePairWithSocketToHost 上的错误访问 exc_i386_gpflt

bad access exc_i386_gpflt on CFStreamCreatePairWithSocketToHost

我正在尝试与我的服务器建立 TLS 连接,但在

上出错了
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, str, 5555, &readStream, &writeStream); 

无法访问 exc_i386_gpflt。我该如何解决?

完整代码

CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFStringRef str = (CFStringRef)"127.0.0.1";
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, str, 5555, &readStream, &writeStream);
if (readStream && writeStream) {
    CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
    CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

    NSInputStream *inputStream = (__bridge NSInputStream *)readStream;
    [inputStream setDelegate:self];
    [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [inputStream open];

    NSOutputStream *outputStream = (__bridge NSOutputStream *)writeStream;
    [outputStream setDelegate:self];
    [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [outputStream open];
}

if (readStream)
    CFRelease(readStream);

if (writeStream)
    CFRelease(writeStream);

试试这个:

CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)HOST, PORT, &readStream, &writeStream);