Question

I don't need precise location data, and I don't want the user to see the "This App wants to determine your location" Alert. I just need to determine the user's country, assuming they have an internet connection via network or wi-fi.

What is the best way to do this? Is there some way to use their IP?

This would only work if they had a carrier:

CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mcc = [carrier mobileCountryCode];

And NSLocale is not reliable in that the user can change it in their device settings. Can't use the device's language setting for the same reason. I need the country based on where they are physically located.

Was it helpful?

Solution

You could get the user's IP address and use a geolocation database to guess their location based on that as described here: https://en.wikipedia.org/wiki/IP_address_location . If you are just concerned with region, you can probably find some data at regional internet registries (https://en.wikipedia.org/wiki/Regional_Internet_registry) websites to help you, since they control all the IP addresses for a particular region.

OTHER TIPS

Refer this url How can whatsapp know country code upon first run on iphone.. Hope this question and the question in the url i have given works for you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top