How to determine app store country

Hello,

My game app will go to andriod and ios app store. The game also has some extra features that requires backend data, I am using google cloud functions and firestore for that purpose. I understand that users playing from China won’t be able to use those google based api. So I am planning to remove those extra features only from users playing from China ios store. Is there any way in solar2d to figure out what country the user is playing from to do something like that:

if user_app_store_country == "cn" then
   -- remove google cloud api based features.
else
   -- init all google cloud api based features.
end

Thank you

Sure … using system.getPreference:

local user_app_store_country = system.getPreference("locale", "country")
print("Country: " ..user_app_store_country)  -- For example, "CN" for China

if user_app_store_country == "CN" then
    -- remove google cloud api based features.
else
    -- init all google cloud api based features.
end

Take a look at the documentation:

1 Like

Yes, thank you, but I am not sure how it will work for a person say living in the USA but using Chinese as default language on their phone settings, I wouldn’t want to restrict them since they can easily access the google based api.

Thank you.

Edit: I double checked on my phone, I can only change the language to Chinese simplified while keeping the region still USA, in that case checking the region part of the locale

local user_app_store_country = system.getPreference("locale", "country")

should work as expected, thank you again.

1 Like

system.getPreference("locale", "country") is only for the country setting. The language is a separate configuration. So, if you wanna check the language simply use system.getPreference( "locale", "language" ) and it return the operating system language code in standard two-letter format. For chinesse language will be “cz”.

1 Like