0

I want ti evaluateJavaScript() which is a function from WKWebView I get the error with detail is:

Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

Can any one met this problem? Hope to your share.Thanks!

Huy Nguyen
  • 77
  • 1
  • 12

1 Answers1

1

You can check the JavaScriptCore framework to evaluate JavaScript. it is native iOS framework.

let context = JSContext()

let _ = context?.evaluateScript(evaluateScriptJSCode)

let method = context?.objectForKeyedSubscript("methodToCallInJavaScript")

let result = method?.call(withArguments: [params])

Raj Aggrawal
  • 761
  • 1
  • 6
  • 21
  • Thanks @Raj Aggrawal, But I mean I just do a very simple action in here. I want to evaluate a javascript string `status=200` and after that I handle with another params in `evaluateJavascript()` in completion block, but with another device it's supported but with the iOS 10.3.3 it show the message I've attached above. – Huy Nguyen Feb 02 '18 at 05:20
  • @bryan you are loading js in Webview and showing to user or just Evaluate. if just evaluate and use the result than JavaScriptCore can do your task easily and effectivly. AS I have evaluate long and complex JS. – Raj Aggrawal Feb 02 '18 at 09:43
  • 1
    Thanks @Raj Aggrawal. I have solve that like your code =)) – Huy Nguyen Feb 03 '18 at 09:23
  • 1
    @Bryan Great to have solution. – Raj Aggrawal Feb 06 '18 at 12:46