leojg
leojg

Reputation: 1186

Objective-C iOS catch a js/html event

Im just starting with objective-c/ios and i am trying to catch an event from html embebed in a uiwebview.

In android you can do it with a js interface.

I already manage to call a js function from ios, now i need to do the opposite.

Thanks.

Upvotes: 0

Views: 553

Answers (2)

rajan0606
rajan0606

Reputation: 1

You can achieve this by using the phone gap framework in objective C. I have used the same in my phonegap project to call the device token.

Here is the sample which is used in javascript.

                                                                                                                                   cordova.exec(null, null, "deviceCls", "getDeviceToken", [args]

You have to point your class(deviceCls) to the phonegap plugin plist.

Check the phone gap links here

Upvotes: 0

Balu
Balu

Reputation: 8460

You can not have Objective-C code mixed with an HTML file that runs locally on a UIWebView. That said, there are some workarounds that may fit your needs.

One that I've used, is to have the HTML link to a custom URL, and detect that on the appropriate method in the UIWebView delegate class, as follows:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

In that method, you would check for the URL schema you created by means of checking the request parameter, and then decide what selector to code on your Objective-C code.

see this blog for simple function call.

another blog for your reqirement

Upvotes: 1

Related Questions