简体   繁体   中英

Get users countrycode (ISO 3166-1) in MonoTouch

I see that the NSLocale bindings aren't complete in MonoTouch so I am having a bit difficulties writing them myself.

Does anyone have the code to get the users countrycode in ISO 3166-1 alpha 3 format? Three letters for each country: http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3

This is being ported from Android where we already have the API call:

Locale.getDefault().getISO3Country();

Have a look at Iphone, Obtaining a List of countries from MonoTouch - it should cover it (or easily be adapted to do so).

note: this will be part of a future version of MonoTouch (got the code in a backup waiting for my iMac reparation ;-)

EDIT

iOS NSLocale returns the ISO 2 letters country code not the ISO 3 letters you're looking for. The best you can do is build a map from 2->3 letters and use the linked code to get the 2 letters code. There's some code to do the reverse (that you can adapt) or even a map (to reverse) available in: Converting country codes in .NET

Note that depending on your requirements this could be incomplete and not exactly matching what Android provides you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM