wk下addObserver后未释放导致的闪退

bug描述:

An instance 0x10e2a8c00 of class WKWebView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x17443b3c0> ( <NSKeyValueObservance 0x174654ca0: Observer: 0x10deef750, Key path: title, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x174654cd0> )

原因:

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    [self.mWebView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];

}

解决方案:

在dealloc中添加释放代码

-(void)dealloc{

    [self.mWebView removeObserver:self forKeyPath:@"title"];

    [[NSNotificationCenter defaultCenter] removeObserver:self];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容