A Sample Of Apple's Phone Number Detection
I'm working on a webapp and I have been struggling with disabling phone number detection in uiwebviews on ios but I believe after a bit of trial and error I may have something that works.  You may think uiwebviews and mobile safari are the same so it shouldn't matter.  Or you may think uiwebviews don't concern you.  Your just a web developer after all.  Well apple just might surprise you.  Jump past the break for a review of the situation and how I solved it.



First, I think it a little bit of background is in order.  In mobile safari apple provides a metatag for disabling phone number detection for the entire page.



While not the greatest solution, when in ios sometimes you take what you can get.  You can always manage phone numbers yourself if you want.

There is a caveat though.  One thing to think about is if a user adds your webapp to the home screen ios will open it up in a uiwebview which for some reason plays by different rules from mobile safari.  The difference relevant to this article is that you will notice your phone number detection is no longer disabled.  Uiwebview does not acknowledge the metatag so were back to square one.

Some have suggested that you can add datadetectors="off" or x-apple-data-detectors="false" to a tag or more specifically an anchor tag and this will supress the phone number detection but I have not seen anything to suggest either of those have any affect in a uiwebview.

Another option open to those who are embedding a uiwebview in their native ios app have is to use dataDetectorTypes from objectiveC.

webView.dataDetectorTypes = UIDataDetectorTypeNone


More on that option can be found here and here.


As I said before though dataDetectorTypes is only an option for embedded uiwebviews where you have access to objectiveC and again this is a page wide disabling of phone number detection.  


After futzing with this for a while I found what I think is the simplest hack for solving this problem.  I found that if you wrap the text you are trying to prevent form being converted into a phone number in an anchor tag with an href="#" uiwebview will leave it alone and vuala no auto detected phone numbers.





Uiwebviews can be quirky little monsters but this seemed to work perfectly for me.  If you have anything to add or this isn't working for you post in the comments.  I would be interested to check out the code.

2 Responses so far.

  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.

  2. Try this Code,

    webView.dataDetectorTypes = UIDataDetectorTypeNone;

    This may help you.

Leave a Reply