簡體   English   中英

javascript ValueCallback 在 swift 中不起作用

[英]javascript ValueCallback not working in swift

我在下面有這個 javascript 代碼,我想在 swift 中運行以提取 html,但我收到以下錯誤:在 scope 中找不到 ValueCallback。

view.evaluateJavascript(
    "(function() { return ('<html>'+document.getElementById('html').innerHTML+'</html>'); })();",
    new ValueCallback<String>() {
        @Override
        public void onReceiveValue(String html) {
            print(html);
        }
    }
);

evaluateJavascript function 有不同的簽名

/* @abstract Evaluates the given JavaScript string.
  @param javaScriptString The JavaScript string to evaluate.
  @param completionHandler A block to invoke when script evaluation completes or fails.
  @discussion The completionHandler is passed the result of the script evaluation or an error.
  Calling this method is equivalent to calling `evaluateJavaScript:inFrame:inContentWorld:completionHandler:` with:
    - A `frame` value of `nil` to represent the main frame
    - A `contentWorld` value of `WKContentWorld.pageWorld`
    */
  open func evaluateJavaScript(_ javaScriptString: String, completionHandler: ((Any?, Error?) -> Void)? = nil)

您需要將代碼更改為

view.evaluateJavascript("(function() { return ('<html>'+document.getElementById('html').innerHTML+'</html>'); })();") { value, error in
  print(value)
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM