Hi.

I have an HTML+JS widget that I'd like to use in a native iOS app.
My idea was to create a subclass of CDVViewController that loads the
HTML+JS code of my widget, and expose some native APIs that actually call
JavaScript functions.

The CDVViewController let me access the underlying UIWebView through the
webView property, so that I can call -[UIWebView
stringByEvaluatingJavaScriptFromString:] to execute some arbitrary JS code.

So I would do something like this:

@interface MyWidget : CDVViewController

-(NSString*)myAPIFunction;

@end

@implementation MyWidget

-(NSString*) myAPIFunction{
return [self.webView    stringByEvaluatingJavaScriptFromString:@
"someJavaScriptFunction();"];
}

@end

Problem is that I must make sure to call JavaScript code ONLY AFTER I'm
sure the UIWebView has finished loading the HTML code, otherwise the
JavaScript functions I need to call woud not be available yet.
What is the correct way to achieve this?
Should I register for the CDVPageDidLoadNotification and call JavaScript
from iOS only after I receive that notification or is there another way to
do that?

Thanks.

Mirko

Reply via email to