UIWebView在子线程创建crash

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];
        });
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容