You can do it by using a custom protocol. In you html file, you can link to something like myProtocol://callSomeAction
.
Then on your UIWebViewDelegate
(probably your UIViewController
) you have to implement the method called:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
(Docs here)
The idea is that on that code, you detect the protocol based on the data in the request
parameter. If it is myProtocol
, you can call your IBAction
and return NO
. If it's something else, you fallback to have the web view load the page, and just return YES
.
The code would look something like this:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString* scheme = [[request URL] scheme];
if ([@"myProtocol" isEqual:scheme]) {
// Call your method
return NO;
} else {
return YES;
}
}