MobileEntityLogo.png

Hi.

Welcome to the best online resource for IOS & Android tutorials.

Getting the users country using NSLocale

To get the users country we have to do the following.

  • First instantiate the NSLocale to get the current information from the device.

  • Then get the country code

  • Then we create a variable that translate the country code into a string with the name of the country such as “US”, “GB” etc.

NSLocale demo code snippet

With the code above we are checking if the user is in the US. If the user is not in the US then we return a string with “User is outside the US”. In my current project we use this to determine whether we want to display metric, or imperial based on the users country.

A little secret about NSLocale

When the user travels outside their home country the locale does not change. The locale is based on the users settings, not their location.

How to fetch image from URL with SwiftUI the easy way

How to fetch image from URL with SwiftUI the easy way

How to add color gradient as Text color in SwiftUI

How to add color gradient as Text color in SwiftUI

0