I found a way to find the country a user is currently in, without using GPS or an Internet Connection.. it's a great if you only need country-level location and, in my case, for a touristic app, where often users turn off their Mobile Data

Works on iOS 8, haven't tested it on older versions of iOS

Sooo, this is what I'm doing:

- (NSString *)findCurrentCountry
{
    // This is the location of the operator symlink
    static NSString * operatorPListSymLinkPath = @"/var/mobile/Library/Preferences/com.apple.operator.plist";

    // Here we get the path where the symlink points to
    NSFileManager * fileManager = [NSFileManager defaultManager]
    NSError * error;
    NSString * operatorPListPath = [fileManager destinationOfSymbolicLinkAtPath:operatorPListSymLinkPath error:&error];

    // The symlink contains a few numbers, of which the first 3 are the MCC of the provider
    operatorPListPath = [operatorPListPath stringByTrimmingCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"1234567890"] invertedSet]];
    NSString * countryMCC = [operatorPListPath substringToIndex:3];

    // Here I return the country from a MCC -> Country dictionary
    return [Helper countryForMCC:countryMMC]; 
}

Let me know what you think! :)

MCC list on Wikipedia: Mobile country code

Related posts

Recent Viewed