gpt4 book ai didi

ios - 无法在 currentRunLoop only MainRunLoop 上安排 NSStream

转载 作者:行者123 更新时间:2023-11-28 22:00:51 24 4
gpt4 key购买 nike

我正在尝试在并发 NSOperation 中使用 NSInputStream。

我注意到我不能在当前运行循环上安排它,只能在主运行循环上安排。为什么是这样?我是否需要为 NSOperation 所在的线程创建自己的运行循环?

代码如下:

{
NSURL *filePath = [Utils getFullFileURLFromFileId:self.fileId];
NSString *filePathString = [filePath path];
self.iStream = [[NSInputStream alloc] initWithFileAtPath:filePathString];
self.iStream.delegate = self;
[self.iStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[self.iStream open];

}

#pragma mark - NSStreamDelegate

- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{
// do stuff
}

最佳答案

确保您安排直播的运行循环确实在运行,并且以您安排直播的模式运行。如果运行循环没有运行,你的流也不会做任何事情。

关于ios - 无法在 currentRunLoop only MainRunLoop 上安排 NSStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25147991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com