Use a wrapper class to prevent a circular reference between the web view and the article controller
This commit is contained in:
parent
acbbee870e
commit
0182fb7296
|
@ -112,7 +112,7 @@ class ArticleViewController: UIViewController {
|
||||||
webView.uiDelegate = self
|
webView.uiDelegate = self
|
||||||
|
|
||||||
webView.configuration.userContentController.removeScriptMessageHandler(forName: MessageName.imageWasClicked)
|
webView.configuration.userContentController.removeScriptMessageHandler(forName: MessageName.imageWasClicked)
|
||||||
webView.configuration.userContentController.add(self, name: MessageName.imageWasClicked)
|
webView.configuration.userContentController.add(WrapperScriptMessageHandler(self), name: MessageName.imageWasClicked)
|
||||||
|
|
||||||
// Even though page.html should be loaded into this webview, we have to do it again
|
// Even though page.html should be loaded into this webview, we have to do it again
|
||||||
// to work around this bug: http://www.openradar.me/22855188
|
// to work around this bug: http://www.openradar.me/22855188
|
||||||
|
@ -378,6 +378,21 @@ extension ArticleViewController: WKScriptMessageHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WrapperScriptMessageHandler: NSObject, WKScriptMessageHandler {
|
||||||
|
|
||||||
|
// We need to wrap a message handler to prevent a circlular reference
|
||||||
|
private weak var handler: WKScriptMessageHandler?
|
||||||
|
|
||||||
|
init(_ handler: WKScriptMessageHandler) {
|
||||||
|
self.handler = handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||||
|
handler?.userContentController(userContentController, didReceive: message)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: UIViewControllerTransitioningDelegate
|
// MARK: UIViewControllerTransitioningDelegate
|
||||||
|
|
||||||
extension ArticleViewController: UIViewControllerTransitioningDelegate {
|
extension ArticleViewController: UIViewControllerTransitioningDelegate {
|
||||||
|
|
Loading…
Reference in New Issue