ios: how to detect if a custom url scheme link failed?

2k views Asked by At

I have an HTML page containing a link to a custom URL scheme, displayed on iPhone .e.g myapp://localhost/

Assuming the user clicks it, but there is no app that can respond to this scheme, how do I catch this in javascript (that the link cannot be opened)?

tnx

1

There are 1 answers

3
Vaibhav Gautam On

Yes that can be done using webview delegate not using Javascript.

Similar question How to handle app URLs in a UIWebView?

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

// Determine if we want the system to handle it.
NSURL *url = request.URL;
if (![url.scheme isEqual:@"http"] && ![url.scheme isEqual:@"https"]) {
    if ([[UIApplication sharedApplication]canOpenURL:url]) {
        [[UIApplication sharedApplication]openURL:url];
        return NO;
    }
}
return YES;
}