1

I'am trying to do this function in Swift 3

self.dict = result as! [String : AnyObject]
self.webView.stringByEvaluatingJavaScript(from: "setFacebookResult(\(self.dict),\(self.userToken))")

I have to pass the token and the result to a global function in javascript but this params dont go correctly to the method. Pls help me!

4
  • Where you are calling stringByEvaluatingJavaScript ? Commented Jan 10, 2017 at 17:06
  • right there, when i pass int values go correctly but strings go wrong Commented Jan 10, 2017 at 17:14
  • What you mean by right there, when i pass int values go correctly but strings go wrong, In your code you are passing Dictionary not string. Commented Jan 10, 2017 at 17:15
  • well, i call this function inside graphRequest.start if error == nil Commented Jan 10, 2017 at 17:19

1 Answer 1

1

You have to format it correctly for javascript.

Note that when using strings, you can't do something like:

let aString = "myTestString"
self.webView.stringByEvaluatingJavaScript(from: "var myString = \(aString)")

instead you have to format it with "":

let aString = "myTestString"
self.webView.stringByEvaluatingJavaScript(from: "var myString = \"\(aString)\"")
Sign up to request clarification or add additional context in comments.

1 Comment

I can resolve the issue converting the result to JSON and use the JSON as param. Ty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.