I need to export contacts phone numbers from the user address book to a remote server.
My server expecting a normalized phone number,
for example if I get contact number: (541) 754-3010
the normalized number should be: 5417543010

my question is about the country code, I want to detect if a number already include a country code and if not to set it myself.

It would be nice if I could query the ABRecordRef to know if a country code exists, but I don't think I can.

Any ideas?

有帮助吗?

解决方案

1) I am guessing that you want to strip brackets and whitespace so you can store the number as an integer instead of a string. This is a bad idea as telephone numbers are not restricted to integers and may contain letters and special characters. (Apple itself uses "1800MYAPPLE").

2) You can check whether the value in kABPersonAddressCountryCodeKey matches the first few characters of your number and, if it doesn't, add them yourself. This is a little dangerous and you should just trust the user to supply a correct number.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top