阻塞主线程遇到的问题

2020-08-04  本文已影响0人  靠北的北

在网络请求时为了等到请求结果采取阻塞线程等待的方式,在main thread中不能使用NSDefaultRunLoopMode会导致runloop休眠,导致任务无法继续执行。主线程中使用NSRunLoopCommonModes

 while (wait) {
        //这里线程等待回调有结果再往下执行
        [[NSRunLoop currentRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate distantFuture]];
    }
上一篇下一篇

猜你喜欢

热点阅读