Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

javascript - How to evaluateJavaScript when app goes to background WKWebView?

I am create html page with HTML5 IMA SDK player and then load this page to WKWebView, all work fine pause, playing content etc, but I want "pause" content when app goes to background for achieve this I did tried used "WKWebView evaluateJavaScript" but this code don't work when app goes to background and did tried this answer (https://stackoverflow.com/questions/53482566/wkwebview-doesnt-run-javascript-when-on-background#:~:text=Javascript%20is%20disabled%20by%20default,WKWebView%20should%20look%20like%20this.&text=Also%20you%20can%20check%20this%20post%20to%20see%20a%20different%20approach) but this don't help me, keyWindow is deprecated and I use another approach:

let keyWindow = UIApplication.shared.connectedScenes
            .filter({$0.activationState == .foregroundActive})
            .map({$0 as? UIWindowScene})
            .compactMap({$0})
            .first?.windows
            .filter({$0.isKeyWindow}).first 

Also doesn't work.

Which way exist for "evaluateScript" when app goes to background or before app will go to background?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...