请耐心等待,我是一名新程序员。(我说的可能没有道理)
我正在尝试创建一个 inputStream 和 outPut 流,以便我可以使用类中其他地方的 JSON 对象对其进行写入...
我想知道我是否做得对。目前,我在 -(id)init{} 中打开流
-(id)init{
_isNetworkAvailable = FALSE;
//kCFAllocatorDefault is the same thing as Null
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)requestURL, port, &readStream, &writeStream);
NSInputStream *inputStream = (__bridge NSInputStream *)readStream;
NSOutputStream *outputStream = (__bridge NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
//There should really be some checking going on here, but we're going to forget it for now
//Call some checking method
_isNetworkAvailable = TRUE;
return self;
}
我的问题是:这是处理此类事情的正确方法吗?我应该在其他地方声明 NSInputStream 和 NSOutputStream 吗?
为什么我必须将我的 CFStreams 转换为 NSStreams?