Luda
Luda

Reputation: 7058

After deiniting webView, video embedded in the webView is still playing - iOS

My ViewController has a WKWebView that embeds JavaScript with a video. When I pop the view controller, deinit is called. In deinit, I nullify everything that related to webView.

However, after popping the view controller, the audio from the video is still playing. What am I missing?

deinit
{
    webView.removeObserver(self, forKeyPath: "estimatedProgress")
    webView.navigationDelegate = nil
    webView.scrollView.delegate = nil
    webView.removeFromSuperview()
    webView = nil
}

Upvotes: 4

Views: 1871

Answers (2)

Luda
Luda

Reputation: 7058

This is what fixed the issue:

override func viewWillDisappear(animated: Bool)
{
    super.viewWillDisappear(animated)

    webView.removeFromSuperview()
}

override func viewWillAppear(animated: Bool)
{
    super.viewWillAppear(animated)

    self.view.addSubview(webView)
}

Upvotes: 0

Aruna Mudnoor
Aruna Mudnoor

Reputation: 4825

I am sure it is because of some cycled retains of the webView. Try by setting empty data to webview in 'deinit'. This may solve your problem, but you have to fix cycled retain of your webview.

webView.loadRequest(NSURLRequest(URL: NSURL(string: "about:blank")))

Upvotes: 4

Related Questions