系统 : iOS 13.3.1
机型: iPhone7

dispatch_async(_jsContextQueue, ^{
JSContext *jscontent = [[JSContext alloc] init];
[UIWebView class];
});
看代码,按照正常思维理解, [UIWebView class]是无论如何都不应崩溃的。
起初按照惯性思维去查找僵尸变量,忙活了半天没有定位。
最终定位结果如下:
在没有调用过UIWebView的任何方法时,先在非主线程中调用UIWebView方法,则会导致崩溃
本文的相关代码如下
#import "ViewController.h"
#import <JavaScriptCore/JavaScriptCore.h>
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
dispatch_queue_t _jsContextQueue;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_jsContextQueue = dispatch_queue_create("jscontext", NULL);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_async(_jsContextQueue, ^{
JSContext *jscontent = [[JSContext alloc] init];
[UIWebView class];
});
});
}
@end

探讨在iOS13.3.1环境下,于非主线程中调用UIWebView导致应用崩溃的现象。分析指出,在未调用UIWebView任何方法前,直接在非主线程调用UIWebView会触发崩溃,并提供代码示例。

被折叠的 条评论
为什么被折叠?



