尝试从主线程或Web线程以外的线程获取Weblocking。 现在崩溃了
bool _WebTryThreadLock(bool), 0x8053ce0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
我得到这个错误。
今天我第一次发现了这个错误,显示了密码对话框,并且alertview显示在顶部,直到viewWillAppear显示视图时才会出现。 这一切似乎工作得很好,当我有一天发展这一点。 不知道为什么线程锁已经丢失,怎么实现呢?
This may be a result of calling to UIKit from a secondary thread. Crashing now...
…就我所知,这就是你正在做的事情。 你正在调用[alertProgress dismissWithClickedButtonIndex:0 animated:YES];
,一个UIKit方法,从一个线程而不是你的主线程,这是不允许的。
如果你不能使用GCD,那么直接回到主线程就可以看看DDFoundation 。
你的代码在这种情况下只会改变;
[[alertProgress dd_invokeOnMainThread] dismissWithClickedButtonIndex:0 animated:YES];
当我正在调用方法时,我也遇到了这个问题
[self performSelector:@selector(myMethod) withObject:nil afterDelay:.01];
现在已经通过在主线上执行来解决了
[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:NO];
如果你打算做任何UI操作,它必须在主线程上完成。
只需将代码粘贴到以下语法中
dispatch_sync(dispatch_get_main_queue(), ^{ //Your code goes here });
或者您可以使用以下语法调用您的方法
[self performSelectorOnMainThread:@selector(yourmethod:)withObject:obj waitUntilDone:YES]
希望这可以帮助
//最简单的方法是使用主线程调用函数。
dispatch_async(dispatch_get_main_queue(), ^{ [self doSomething]; });
我有一个类似的问题,并使用
performSelectorOnMainThread:withObject:waitUntilDone:
解决它。 希望有所帮助。
杜蕾斯在Swift 3中回答:
DispatchQueue.main.async { //Your code goes here }