3

Purpose: I want to call objective C code from a Javascript in iOS Webview in RubyMotion

I am loading a index.html file in iOS web View. And it has one button

<button type='button' onclick='alert();'>Hello!</button></div>

My webview code

def webViewDidFinishLoad(webView)

context =  @webView.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext")
//jsFunctionText = "var sayHello = function() {alert('hi')}"
context.evaluateScript(jsFunctionText)

context["sayHello"] = lambda {
  App.alert("this is nice")
}

context.evaluateScript("sayHello();");

end

Somehow the popup is not displaying on clicking the button. I am doing something silly.

0 Answers0