views:

46

answers:

1

Is it possible to communicate between Objective-C and JavaScript? Call a JavaScript function from Objective-C. Call Objective-C function from JavaScript? If so how?

A: 

If you are using UIWebView to host your html+javascript you can use the

 stringByEvaluatingJavaScriptFromString:
method to evaluate a javascript fragment (and call your JS functions from that).
Calling ObjC code from javascript would be complicated: for what I know you can only call JS code from ObjC, but not viceversa.
You could periodically call a certain JS function from ObjC and use the returned string to select some action to perform in ObjC.
Kind of hackish, I think, but I have no other ideas.

garph0