Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telephone area code to city name on iOS

On Apple's built-in Voicemail app, when it finds a phone number it does not recognize in your address book, it displays an approximate location under the number, presumably based on the phone number. How did they do that?? I'd guess there's a large database of area codes and exchange numbers on the phone, each mapping to a city or region name. Does anyone know if this mapping is accessible to apps via a public API?

There's lots of boilerplate code out there for mapping ZIP code to city, but I don't see much that does the same with area code / exchange. Any ideas?

like image 547
Ryan Avatar asked Oct 09 '22 16:10

Ryan


1 Answers

I've created a plist file that has the area codes and locations in it: areacodes.plist. To use it follow these steps:

If you just won't to use the plist file:

1. Add the plist file to your project.

2. Load the file:

NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"areacodes" ofType:@"plist"];
NSDictionary *areaCodeDict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];

3. Use the dictionary you've loaded. The keys are the area codes, the values are the locations:

NSString *areaCode = @"801";
NSString *location = [self.areaCodeConversion objectForKey:areaCode];
NSLog(@"%@",location); // prints utah

To use the included class:

1. Add the downloaded folder to your project.

2. Use the included class to access the plist information:

#import "AreaCodes.h"
...
AreaCodes *areaCodes = [[AreaCodes alloc] init];
NSString *location = [areaCodes getLocationForCode:@"801"];
NSLog(@"%@",location);
// prints "Utah"
like image 166
Jbryson Avatar answered Oct 11 '22 05:10

Jbryson