dataDetectorTypes phone link issue
this is a reformulation of this question
When i set myWeb开发者_运维技巧View.dataDetectorTypes = UIDataDetectorTypeNone; phone links (in a href html tag) are handled like this :
How can I handle phone links with the shouldStartLoadWithRequest delegate method instead?
I have not still found the cause of the problem but I found a solution.
Instead of writing phone links in anchors like this tel:myphonenumber, i write allo:myphonenumber.
Thus, the shouldStartLoadWithRequest method is called. And i can substitute allo: by tel: in my NSURLRequest
object.
edit, here is the code :
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType; {
NSURL *requestURL = [[ request URL] retain];
// Check to see what protocol/scheme the requested URL is.
if (
// ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] ) &&
( navigationType == UIWebViewNavigationTypeLinkClicked )
) {
// Stats
[self recordTouch: [self tagToZone:[[webView superview] tag]]];
// Substitution allo -> tel
NSURL *newURL = [[NSURL alloc] initWithString: [[[request URL] absoluteString] stringByReplacingOccurrencesOfString: @"allo:" withString: @"tel:"]];
[requestURL release];
//return YES;
// Launch
return ![ [ UIApplication sharedApplication ] openURL: [newURL autorelease]];
}
// Auto release
[requestURL release];
return YES;
}
精彩评论