简体   繁体   English

Objective-C 上的异步调用

[英]Async calls on Objective-C

I'm implementing a mic plugin for a game and since the [capture_session startRunning] function is a long call, I'm wrapping it in an async call, but it is still laggy.我正在为游戏实现一个麦克风插件,并且由于[capture_session startRunning] function 是一个很长的调用,我将它包装在一个异步调用中,但它仍然滞后。

Commenting the code solves the lag, so I'm pretty sure this is the chunk that causes it.评论代码解决了滞后,所以我很确定这是导致它的块。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
   [capture_session startRunning];
   is_recording = true;
                        
   NSMutableDictionary *event = [Utils newEvent:EVENT_NAME];
   event[PHASE_KEY] = @"started";
   event[IS_ERROR_KEY] = @((bool)false);
   [Utils dispatchEvent:lua_listener event:event];
});

Btw, I don't know much the language so I could be doing some very silly things here.顺便说一句,我不太懂这种语言,所以我可能会在这里做一些非常愚蠢的事情。

Really appreciate any help!非常感谢任何帮助!

try this?尝试这个?

dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
    ...
    NSLog(@"current thread ---%@", [NSThread currentThread]);

});

You use concurrent queue and async method, those code you put in block should be run in a new thread.您使用并发队列和异步方法,您放入块中的那些代码应该在新线程中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM