I have an app which uses contact data in the following ways:
- To send an SMS from the client
- To send an SMS from our server
- To upload a user's phone number to a database where others can match against it
This works fine in the U.S. but internationalizing has a set of issues. These are my assumptions for making it work:
#1 - Sending an SMS from the client is straightforward. Use the number in the address book verbatim (without normalization) and let the OS figure it out. Chances are if they can make a phone call via a given number they can send an SMS (right?)
#2/#3 - Sending an SMS from the server is more complicated. Most SMS APIs require international notation (the "+" prefix and country code) whereas the user will have in their contact list a variety of various local and global phone number with various prefixes (area code, country code, etc). So normalization would be required here. Matching a user's phone number in a database also requires normalization.
To normalize phone numbers, I have to first decide if the user meant to specify a global number by looking for "+" "011" and "00" prefixes. If so, I remove the prefix, replace it with "+" and use that number.
If I think the number is local, I can try to tack on the country code myself (heuristic, not reliable). This requires knowing the user's default country code. On the iPhone, I can get the user's preferred region (which is selectable) and the user's MCC and MNC (dependent on location?). I am leaning toward the user's selected country code because chances are most of their local phone numbers will be of that country.
I believe this is the best I can do without parsing the entire number and figuring out area code and other components. I assume most countries allow "0" as a prefix for their own country code.
Make sense? Is there an easier/more sane way to do this?