Stop an NSRunLoop

2020-03-13 08:58发布

I have a connection in a thread, so I add it to the run loop to get all data:

  [[NSRunLoop currentRunLoop] run];
  [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

But I can't find any way to stop it

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    if([NSRunLoop currentRunLoop]){
        [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
    }
    [connection cancel];
}

How can I stop this loop?

1条回答
对你真心纯属浪费
2楼-- · 2020-03-13 09:19

You can stop the runloop by Core Fundation API :

CFRunLoopStop(CFRunLoopGetCurrent());
查看更多
登录 后发表回答