美文网首页
UIWebView在子线程创建crash

UIWebView在子线程创建crash

作者: 似奔跑的野马 | 来源:发表于2018-03-30 10:29 被阅读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];
        });

相关文章

网友评论

      本文标题:UIWebView在子线程创建crash

      本文链接:https://www.haomeiwen.com/subject/eobbcftx.html