WKWebView與UIWebview實(shí)時(shí)監(jiān)測(cè)網(wǎng)頁(yè)title方法
初始化web
- (WKWebView *)webView- {
if (!_webView) {
_webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
_webView.navigationDelegate = self;
}
return _webView;
}
添加觀察者
[self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:nil];
當(dāng)網(wǎng)頁(yè)title改變的時(shí)候執(zhí)行以下方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
self.navigationItem.title = change[@"new"];
}