1

From documentation, it seems to be possible except for the sentence highlighted :

The web scripting capabilities of WebKit permit you to access Objective-C properties and call Objective-C methods from the JavaScript scripting environment.

An important but not necessarily obvious fact about this bridge is that it does not allow any JavaScript script to access Objective-C. You cannot access Objective-C properties and methods from a web browser unless a custom plug-in has been installed. The bridge is intended for people using custom plug-ins and JavaScript environments enclosed within WebKit objects (for example, a WebView).

Or should I consider the solution from Sixten Otto shown here ? What I wish to do is : when user tap on an image in UIWebView a JavaScript routine calls a method in Objective-C.

Community
  • 1
  • 1
Stanley
  • 4,446
  • 7
  • 30
  • 48
  • Duplicate http://stackoverflow.com/questions/7171163/how-do-i-call-an-objective-c-method-from-javascript-on-uiwebview?rq=1 – Lithu T.V May 13 '13 at 11:29
  • http://stackoverflow.com/questions/1662473/how-to-call-objective-c-from-javascript – Lithu T.V May 13 '13 at 11:30
  • possible duplicate of [How to call an Objective-C method from Javascript in a Cocoa/WebKit app?](http://stackoverflow.com/questions/92471/how-to-call-an-objective-c-method-from-javascript-in-a-cocoa-webkit-app) – Jim Puls May 13 '13 at 19:10

2 Answers2

0

Did you see this JavaScriptFromObjC

and this question

Community
  • 1
  • 1
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
  • Thanks for the answer. Yes, I saw those. But I am hoping for a more proper way instead of workarounds like using a URL. – Stanley May 13 '13 at 11:35
  • 2
    URL schemes are not a 'workaround,' they are the only official Apple sanctioned way of doing this type of communication. – Owen Hartnett May 13 '13 at 20:04
  • Owen and Lithu, I think you are right. After spending exceedingly more time on this topic than I'd expected, it becomes apparent that there wouldn't be any formal API for this type of communication. The likely reason is there had been a trade off between security and flexibility. It would be quite a security concern if some downloaded code from the web can freely call any local methods on the device. – Stanley May 14 '13 at 07:16
0

Take a look at open source project Apache Cordova. You'll learn how to interact with native code for other mobile platforms, too.

Aleš Kotnik
  • 2,654
  • 20
  • 17
  • I took a look at your link. It's surely worth looking into even though I am not thinking of using it at least for the moment. – Stanley May 14 '13 at 07:06