UIWebView在子线程创建crash

2018-03-30  本文已影响0人  似奔跑的野马

UIWebView初始化创建,需要在主线程执行,否则会crash。

dispatch_async(dispatch_get_global_queue(0, 0), ^{
            NSString *webViewUserAgent = [NSMutableString stringWithString:[[UIWebView new] stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]];
        });
错误记录

bool _WebTryThreadLock(bool), 0x170016010: 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...
正确的初始化,就是在主线程创建。如多线程时,防止子线程调用,最好初始化

  dispatch_async(dispatch_get_main_queue(), ^{
            UIWebView *webView = [UIWebView new];
        });
上一篇 下一篇

猜你喜欢

热点阅读