Calling Objective C code from Javascript in Rubymotion

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

I am loading index.html file into iOS webview. And it has one button

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


My web code

def webViewDidFinishLoad(webView)

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

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




Somehow the popup is not showing when the button is clicked. I am doing something stupid.


source to share

All Articles