1

I am developing an iPhone app. At one point, the user types phone numbers. These can be in any format, international or local. Local format would be something like 514-123-4567 (or worse, just 123-4567), is there a way to convert local phone numbers to the international format (E.164): +15141234567? This means finding out what the country is (and perhaps the region too, if possible).

One way would be to require the user to always enter phone numbers using the international format, or to select the country she's in. But if I can avoid that, I think it would be more user friendly.

I would also like to avoid asking the user for the authorization to geolocate her: a lot of users refuse geolocation.

Ideally, I would like to get the country and region of her own phone number. Or perhaps the current carrier's country (in case the user is roaming in another country than hers).

But what if she installed the app on an iPod or iPad without a SIM card? Maybe I could use the locale? Or I could try to geolocate the IP address?

Any better ideas?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
MiniQuark
  • 46,633
  • 36
  • 147
  • 183

1 Answers1

1
  1. For "converting" phone numbers - you have an example here: STPhoneFormatter

  2. You can use NSLocale to determine how to localize your customer - but not allays determine where the user is (locale and language are both user-configurable). If you really want to find out what country the phone is in right now, use geolocation.

here a NSLocale example for countryCode/country:

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];  
TonyMkenu
  • 7,597
  • 3
  • 27
  • 49
  • Tx. Isn't there a way to get the carrier's country? – MiniQuark Sep 25 '13 at 07:36
  • Yes, there is somethings.. you can get SIM info.. CTCarrier, but the value does not change if the user is roaming (info just about SIM's s cellular service provider) https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html – TonyMkenu Sep 25 '13 at 08:23
  • I you want to find the location of the user .. you must use CoreLocation; check this :) https://github.com/HeshamMegid/HMDiallingCode – TonyMkenu Sep 25 '13 at 08:27