0

首先让我说我是一个完全的 Objective-c 新手,我正在使用现有的代码库,所以我正试图疯狂地阅读 NSRunLoop 等,但我希望得到一些额外的帮助。

基本上,我继承了如下代码:

[[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantFuture]];
[_captureSession startRunning];
return [NSNumber numberWithInt:0];

在一个应该返回的函数中,而是在 startRunning 上永远阻塞。我需要这个来返回,我不确定它为什么会阻塞。一些分散的代码可能会有所帮助:

_captureDecompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc]
                                    init];
[_captureDecompressedVideoOutput setDelegate:self];
[_captureDecompressedVideoOutput performSelectorOnMainThread:@selector(setPixelBufferAttributes:) withObject:captureDictionary waitUntilDone:NO];

知道发生了什么吗?

4

1 回答 1

0

好吧,我将 [_captureSession startRunning] 卡在一个单独的函数中,然后将调用替换为

self performSelectorInBackground:@selector(backgroundCapture) withObject:nil];

所以它在一个线程中运行。阻塞不仅不会干扰方法返回(因为它在单独的线程上),而且调用甚至不会阻塞,因为它正在自己的线程上运行。奇怪。

于 2012-08-14T23:22:50.950 回答