Get Javascript function response in iOS using Swift

Mamta Kaundal picture Mamta Kaundal · Feb 26, 2016 · Viewed 8.2k times · Source

I am trying to figure out how to implement JavaScript functions inside my iOS app using swift platform .

I have tried out the example code specified in the link

https://tetontech.wordpress.com/2014/07/15/swift-to-javascript-and-javascript-to-swift-a-round-trip/

But i want in the same way like android is doing as specified in the link http://android-er.blogspot.in/2011/10/call-javascript-inside-webview-from.html

Could you please help me out.

Any help will deeply appriciated.

Answer

May Rest in Peace picture May Rest in Peace · Feb 26, 2016

If you are using WKWebView you can call javascript by using

webView.evaluateJavaScript("YourJavaScript",completionHandler : nil )

For UIWebView you can use

  webview.stringByEvaluatingJavascriptFromString : @"YourJavaScript";