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

bug描述:

An instance 0x10e2a8c00 of class WKWebView was deallocated while key value observers were still registered with it. Current observation info: ( 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];

}

你可能感兴趣的:(wk下addObserver后未释放导致的闪退)