I want to integrate a full HTML framework (ie HTML/CSS/JavaScript) inside an iOS app and make the UIWebView in charge of running the HTML content being able to communicate with the rest of the native Objective-C source code.
Direction 1: from Objective-C to HTML inside a UIWebView
The way to make the rest of the source send messages to the HTML content is pretty straightforward: i can just call stringByEvaluatingJavaScriptFromString: on the Objective-C side and implement JavaScript methods the right way.
Direction 2: from HTML inside a UIWebView to Objective-C
This is the way I can’t really figure out. My only idea so far is to make my app a local web server and make the HTML request stuff to it. But I have no idea how to do that although I suppose it can be bone as I believe apps such as Things, VLC or 1Password might use this kind of features.
Any idea to make this direction 2 work or any new perspective to make events inside HTML content being sent to Objective-C code is welcome.
I have done this using jQuery and UIWebViewDelegate:
JavaScript (jQuery mobile):
So, the resulting URL looks like:
donordialog:bloodTypeChanged(typeAB-)In my objc code:
This code was copied verbatim from a project I am currently working on, and can verify that this works.