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.evaluateScript(jsFunctionText)

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

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

      

end

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

+3
javascript ios ios7 javascriptcore rubymotion


source to share


No one has answered this question yet

Check out similar questions:

7649
How does JavaScript blocking work?
7494
How can I remove a specific element from an array in JavaScript?
7432
How to check if a string contains a substring in JavaScript?
7287
What does "use strict" do in JavaScript, and what are the reasons for it?
5722
How can I remove a property from a JavaScript object?
5670
Which operator is equal (== vs ===) should be used in JavaScript comparisons?
5129
How do I return a response from an asynchronous call?
5101
What's the most efficient way to deeply clone an object in JavaScript?
4829
How do I include a JavaScript file in another JavaScript file?
3714
How can I check if an array contains a value in JavaScript?



All Articles
Loading...
X
Show
Funny
Dev
Pics