C# 如何获取应用程序的应用商店国家/地区?
我需要一种方法来获取我用Xamarin(Android和iOS)制作的应用程序的国家代码。语言是不够的,因为许多人(像我一样)在手机上使用英语 我已经尝试了以下方法: -RegionInfo.CurrentRegion(返回设置中设置的语言) -CultureInfo.CurrentCulture(返回设置中设置的语言)C# 如何获取应用程序的应用商店国家/地区?,c#,xamarin,xamarin.forms,xamarin.android,xamarin.ios,C#,Xamarin,Xamarin.forms,Xamarin.android,Xamarin.ios,我需要一种方法来获取我用Xamarin(Android和iOS)制作的应用程序的国家代码。语言是不够的,因为许多人(像我一样)在手机上使用英语 我已经尝试了以下方法: -RegionInfo.CurrentRegion(返回设置中设置的语言) -CultureInfo.CurrentCulture(返回设置中设置的语言) -NSLocale类(仅适用于iOS)使用依赖项服务: Shared: public interface IRegionCulture { Cu
-NSLocale类(仅适用于iOS)使用依赖项服务:
Shared:
public interface IRegionCulture
{
CultureInfo GetRegionCulture();
}
Android:
public CultureInfo GetRegionCulture()
{
return new CultureInfo(Java.Util.Locale.Default.ToString());
}
iOS:
public CultureInfo GetRegionCulture()
{
var code = NSLocale.CurrentLocale.CountryCode;
var culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => c.Name.EndsWith("-" + code, StringComparison.Ordinal));
return culture;
}
您可以查看PhilipOchu提供的建议。这是一个新的选择,以获得国家。