Getting the users country

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

andyh1234
Posts: 442
Joined: Mon Aug 13, 2007 4:44 pm
Location: Eccles UK
Contact:

Getting the users country

Post by andyh1234 » Sun Aug 06, 2023 6:46 pm

Is there an easy way to get the users country from the app store or something similar within livecode ios.

Im working on an app that has a regional database, depending on which country the user is in and if possible I would like to pre-fill the country when I ask them as part of the user setup what country they are in.

Thanks

Andy

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Getting the users country

Post by stam » Mon Aug 07, 2023 1:03 am

Hmmm, as far as I know LiveCode has no automatic way of doing this, but I may be wrong.
I'm pretty sure no App Store will give you information on logged in users - but it is possible in Swift and other languages to get a country code associated with the App Store used. This is an informative post: https://stackoverflow.com/questions/493 ... re-country
how this can be applied in LC I'm not sure - but presumably if you're using the App Store to distribute, you may have access to the API.

Alternatively perhaps you could IP geocode users when using the app (although you'd need to clarify this in your EULA and/or seek consent).

If you did go down that route there are a number of alternatives - https://radar.com/product/api?utm_term= ... HxEALw_wcB might be a good one as it's free for up to 100,000 API calls per month and seems relatively cheap if you exceed that limit. You could use its IP geocode API to get the user's location - but that assumes of course they are not on a VPN (but then they may well be using a different country's App Store).

Or you could just get this information directly from the user ;)
I'm pretty sure most users are used to entering a country name - I certainly am ;)

andyh1234
Posts: 442
Joined: Mon Aug 13, 2007 4:44 pm
Location: Eccles UK
Contact:

Re: Getting the users country

Post by andyh1234 » Mon Aug 07, 2023 2:50 pm

Thanks

Ive found a command mobileCurrentLocale() which gives a good indicator as to the country the user is in so this is a good starting point for my drop down box, I can detect a US or GB language and set the country initially to that, beyond that the user will have to select the country themselves.

Thanks for the help.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the users country

Post by richmond62 » Mon Aug 07, 2023 2:57 pm

"a US or GB language" ?

Let's see: US English, GB English, Welsh, Irish Gaelic, Scots Gaelic, Spanish, Pennsylvania Dutch, Louisiana French, Gullah, . . .

What about other languages?

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Getting the users country

Post by stam » Mon Aug 07, 2023 4:03 pm

richmond62 wrote:
Mon Aug 07, 2023 2:57 pm
"a US or GB language" ?

Let's see: US English, GB English, Welsh, Irish Gaelic, Scots Gaelic, Spanish, Pennsylvania Dutch, Louisiana French, Gullah, . . .

What about other languages?
The OP wishes to pre-populate a database based on App Store location, with the user being able to fill in detail.
It's not a language thing. I'm guessing you just read the last sentence of the last post, didn't you?

How does the OP's question and aim apply to Welsh, Irish, Scots, Gaelic 'Louisiana French', Gullah (you really excelled yourself on that one...)? Is there a Gullah app store that I missed? Does this really help in any way?

As my great-grandma used to say: don't feed the trolls, so I'll stop there...

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the users country

Post by richmond62 » Mon Aug 07, 2023 4:33 pm

I wonder what the Gullah for 'troll' is? 8)

How about getting the stack to determine the device's external IP address?

https://forums.livecode.com/viewtopic.php?t=29919

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Getting the users country

Post by stam » Mon Aug 07, 2023 5:16 pm

richmond62 wrote:
Mon Aug 07, 2023 4:33 pm
I wonder what the Gullah for 'troll' is? 8)

How about getting the stack to determine the device's external IP address?

https://forums.livecode.com/viewtopic.php?t=29919
Richmond, that was implied when I suggested one option is to IP geocode.

Getting the IP is not hard, it's what you do with it.
I linked an API that allows 100,000 free API calls for geolocation by IP per month - and assuming this is a process for initial installation/registration I can't really imagine that wouldn't suffice and be done entirely for free - but that does add a level of complexity which probably isn't needed as Andy is happy just to use the country code returned by the App Store.

Now if he wanted to automatically get City, State and Country then the IP geolocation API would be more useful...

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the users country

Post by richmond62 » Mon Aug 07, 2023 5:28 pm

This works for Mac:

https://ipleak.net/

and on Android.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Getting the users country

Post by stam » Mon Aug 07, 2023 5:36 pm

richmond62 wrote:
Mon Aug 07, 2023 5:28 pm
This works for Mac:

https://ipleak.net/

and on Android.
yes - the API for that is found here: https://airvpn.org/forums/topic/14737-api/
+ free, seems to work
- judging by forums, occasionally spotty performance
- less documentation/support than commercial service (even if free)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the users country

Post by richmond62 » Tue Aug 08, 2023 7:57 am

I wonder why this returns NOTHING when the original line refered to contains data?

Code: Select all

find "continent_name" in fld "dLIST"
put line (the foundLine) of fld "dLIST" into fld "bilad"

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the users country

Post by richmond62 » Tue Aug 08, 2023 10:03 am

Mind you, if I could import a URL into a text field like this:
-
SShot 2023-08-08 at 11.58.11.png
-
instead of like this:
-
SShot 2023-08-08 at 12.02.31.png
-
'Life' would be a whole lot easier. 8)

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Getting the users country

Post by stam » Tue Aug 08, 2023 10:17 am

richmond62 wrote:
Tue Aug 08, 2023 7:57 am
I wonder why this returns NOTHING when the original line refered to contains data?

Code: Select all

find "continent_name" in fld "dLIST"
put line (the foundLine) of fld "dLIST" into fld "bilad"
the foundLine is a chunk expression, ie line x of field y, but annoyingly if you try to use this directly (ie put the FoundLine into field "blah") it literally just puts "line x of field y" into field "blah".

So you could either change your code to:

Code: Select all

put line (word 2 of the foundLine) of fld "dLIST" into fld "bilad"
or just get it's value:

Code: Select all

put value(the foundLine) into fld "bilad"


As usual my preference is different: Since the data returned is in JSON format, which is basically a textual representation of a multidimensional array, I would prefer to put this into an array and get it's key - no need to faff around with extra and unnecessary fields and no need to 'clean' the text.

Code: Select all

on mouseUp
   local tArray
   put JSONToArray(URL ("https://ipleak.net/json/")) into tArray
   put tArray["continent_name"] into field 1 
end mouseUp
This is cleaner; the text method you describe populates field "bilad" with "continent_name": "Europe"
Wheres the array just it returns the value and populates the field with Europe
Last edited by stam on Tue Aug 08, 2023 10:20 am, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the users country

Post by richmond62 » Tue Aug 08, 2023 10:19 am

As usual my preference is different
Your value in my eyes would have dropped considerably had it not been. 8)

HOWEVER . . . my mind has wandered to the question I posted just before your reply.

After all, if Mac's 'happy, little' TextEdit can do that, surely LC can do that as well.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Getting the users country

Post by stam » Tue Aug 08, 2023 10:29 am

richmond62 wrote:
Tue Aug 08, 2023 10:03 am
Mind you, if I could import a URL into a text field like this:
<snip>
'Life' would be a whole lot easier. 8)
Ermm... are you just scraping the HTML?
You do realise they provide an API for easy developer access so you don't have to scape the HTML? The JSON I mentioned?
Did you spot the code I used:

Code: Select all

put JSONToArray(URL ("https://ipleak.net/json/")) into tArray
ipleak.net/json/ is key

The text you get back is in JSON format:
JSON wrote:{
"as_number": 15404,
"isp_name": "COLT Technology Services Group Limited",
"country_code": "GB",
"country_name": "United Kingdom",
"region_code": "ENG",
"region_name": "England",
"continent_code": "EU",
"continent_name": "Europe",
"city_name": "London",
"postal_code": null,
"postal_confidence": null,
"latitude": 51.5088,
"longitude": -0.093,
"accuracy_radius": 10,
"time_zone": "Europe\/London",
"metro_code": null,
"level": "min",
"cache": 1691487314,
"ip": "161.17.0.123",
"reverse": "",
"query_text": "161.17.0.123",
"query_type": "myip",
"query_date": 1691487314
}
(don't care about sharing details here as its the public wifi at my workplace)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Getting the users country

Post by richmond62 » Tue Aug 08, 2023 10:39 am

That is fantastic: thank you so, very, very much.
Ermm... are you just scraping the HTML?
More like 'scraping the barrel' in my case: or, put another way: Richmond's ignorance in matters such as JSON.

Post Reply

Return to “iOS Deployment”