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
source to share
No one has answered this question yet
Check out similar questions: