Skip to content

Instantly share code, notes, and snippets.

@mwbrooks
Created February 9, 2011 18:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwbrooks/819020 to your computer and use it in GitHub Desktop.
Save mwbrooks/819020 to your computer and use it in GitHub Desktop.
Disable telephone number detection in PhoneGap-iOS
// ...
- (void)webViewDidStartLoad:(UIWebView *)theWebView
{
// disable telephone detection, basically <meta name="format-detection" content="telephone=no" />
theWebView.dataDetectorTypes = UIDataDetectorTypeAll ^ UIDataDetectorTypePhoneNumber;
return [ super webViewDidStartLoad:theWebView ];
}
// ...
@onlyfrank
Copy link

Hi mwbrooks,

It does indeed work :) but I'm getting a constant error in the console log:

UIDataDetectorTypeLegacyPhoneNumber is incompatible with other types (-2)

..it keeps repeating itself every second :/
Tested under XCode 4.0.2 & Phonegap 1.0.0
Thanks,
Frank

@mwbrooks
Copy link
Author

mwbrooks commented Aug 9, 2011

Hey @onlyfrank,

I've noticed that also. Maybe that approach has been deprecated in XCode 4.x?

@MiketoString
Copy link

any workaround for the console log spamming?

@mwbrooks
Copy link
Author

I think the above gist can be considered deprecated / obsolete. In PhoneGap-iPhone 1.x, you can now open PhoneGap.plist and toggle the boolean DetectPhoneNumber

@MattRogish
Copy link

It doesn't appear that iOS4.x actually pays attention to the boolean. On PG1.0, on iOS4.3, the phone numbers are still clickable. On iOS5 GA, they are not.

@MattRogish
Copy link

I think what it means is that ALL ^ PhoneNumber is logically wrong (given their setup). If I change it to a conjunct of the ones I want (i.e. everything but phone number) the spamming goes away, e.g.

[theWebView setDataDetectorTypes: UIDataDetectorTypeLink & UIDataDetectorTypeAddress];

@shazron
Copy link

shazron commented Oct 12, 2011

Did some tests:

    // pretty obvious, but tmp0 NOT equivalent to tmp below, but what we are doing in tmp is what we want conceptually in tmp0
    NSUInteger tmp0 = UIDataDetectorTypeLink | UIDataDetectorTypeAddress | UIDataDetectorTypeCalendarEvent; 
    // what we want originally
    NSUInteger tmp = UIDataDetectorTypeAll ^ UIDataDetectorTypePhoneNumber; // this ALONE does not produce the warning
    theWebView.dataDetectorTypes = tmp0; // ADDING this does NOT produce the warning
    theWebView.dataDetectorTypes = tmp; // ADDING this produces the warning

Changing compilers to LLVM only, GCC only or LLVM+GCC does not help.

The warning happens in the synthesized function for dataDetectorTypes (more likely it was not synthesized but an explicit function that they constructed setDataDetectorTypes where they do custom verification stuff) which is unfortunately opaque to us. It is best to bitwise OR the values to combine them - setDataDetectorTypes just doesn't like the XORed number somehow.

@MattRogish
Copy link

erp, yes OR

@shanesmith
Copy link

The following seems to work fine for me with XCode 4.3, iOS 5.0.1 and PhoneGap 1.4.1 =)

theWebView.dataDetectorTypes = UIDataDetectorTypeAll & ! UIDataDetectorTypePhoneNumber;

@liyamahendra
Copy link

shanesmith's code worked fine for me as well. Tested it on Xcode 4.5.2, iOS 6 & PhoneGap 1.4.1

@nuvocode
Copy link

You can also disable telephone number highlighting using this meta tag.
meta name="format-detection" content="telephone=no"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment