views:

305

answers:

2

Is the areanything special you need in html or Callbacks in a UIWebView to handle anchor tags with an href, or is there something special about an anchor tag with a mailto link in the href?

+1  A: 

In your UIWebView's delegate, do:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if ([[[request URL] scheme] isEqual:@"mailto"]) {
        [[UIApplication sharedApplication] openURL:[request URL]];
        return NO;
    }
    return YES;
}
cduhn
A: 

I noticed that when running in the iPhone simulator, I could click on an HTTP link in my UIWebView and it would open in Safari, but when I clicked on a mailto link nothing would happen. But when I deployed the app to a real device, it worked. I expect the reason is because there is no mail app on the simulator, but there is Safari.

Josh Justice