I have a HTML form that has certain fields which i am opening inside a UIWebview. On click of a particular button i want to do a in app action.
The approach i\'m usi
This code:
<a class="yourButton" href="inapp://capture">Restart</a>
doesn't work for me.
I've added "inapp://capture" in my javascript code for event function
KeyboardInputManager.prototype.restart = function (event) {
window.location.href = "inapp://capture";
//other code
};
Also I use the UIWebViewDelegate and It works for iOS 8, 9.
For swift 4.2
Button code in HTML side:
<a class="catch-iOS" href="inapp://home">Продолжить покупки</a>
UIWebViewDelegate method:
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {
if request.url?.scheme == "inapp" {
if request.url?.host == "home" {
// do something
}
}
return true
}
You can do the following:
In your HTML
<a class="yourButton" href="inapp://capture">Button Text</a>
In your UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.scheme isEqualToString:@"inapp"]) {
if ([request.URL.host isEqualToString:@"capture"]) {
// do capture action
}
return NO;
}
return YES;
}
I added "capture" to your button's URL so that you could distinguish between several buttons that should trigger different actions (if you want to):