Find Current Country from iPhone Device

Get device location (only country) in iOS

NSLocale is just a setting about currently used regional settings, it doesn't mean the actual country you're in.

Use CLLocationManager to get current location & CLGeocoder to perform reverse-geocoding. You can get country name from there.

Find current country from iPhone device

To find the country of the user's chosen language:

NSLocale *currentLocale = [NSLocale currentLocale];  // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
// get country code, e.g. ES (Spain), FR (France), etc.

In Swift:

let currentLocale = NSLocale.currentLocale()
let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as? String

If you want to find the country code of the current timezone, see @chings228's answer.

If you want to find the country code of the device's physical location, you will need CoreLocation with reverse geocoding. See this question for detail: How can I get current location from user in iOS

How to get current country of Device in React Native (iOS and Android)?

According to the documentation of react-native-device-info for latest version, they have moved some of their apis to react-native-localize to reduce duplication in the react-native-community modules. react-native-localize worked perfectly for me.

Setup:

$ npm install --save react-native-localize
# --- or ---
$ yarn add react-native-localize

Usage:

import * as RNLocalize from "react-native-localize";

console.log(RNLocalize.getLocales());
console.log(RNLocalize.getCurrencies());
console.log(RNLocalize.getCountry());
console.log(RNLocalize.getCalendar());
console.log(RNLocalize.getTemperatureUnit());
console.log(RNLocalize.getTimeZone());
console.log(RNLocalize.uses24HourClock());

and many more. For detailed description please visit their official documentation by the given link: react-native-localize

Determine Country associated with Apple ID logged into the iOS device

Answers to both questions is no (for good reasons). Apple does not provide programmatic access to the device owner's Apple ID. And certainly not any info associated to the credit card. I would go with asking the user permission to get their location and explaining why your app needs it (in iOS 6 you can provide a context for why location is requested).

Get country name of iOS user without using location

There are web API services your app could contact to obtain the rough location of the ip address. It's not at all guaranteed to be the correct country of the device, as your user may be using an out-of-country VPN service, but it's probably the only thing you can do without asking the device for location.

Here's an example service. I know nothing about the quality of this service (I picked this one at random for this answer). There seem to be many out there, so do your homework as to which would be best for your users and yourself.

There's another approach you could take: simply ask the user, and have faith that most of them will answer honestly. If their answer doesn't make sense per the timezone of the device, maybe suspect their answer is false.



Related Topics



Leave a reply



Submit