Changing output depending on users location (Country) - ios

At the moment I have an app on the App Store, which is only available in the U.K., this is because in the U.K., U.S. and the E.U. use different measurements (imperial and metric).
So what I want to know, how would I tell what country a user is from, and in turn know which conversion to use?
Maybe an if statement for Locale? If that's even possible, or an option where the user selects what country they are from (and then save it so they don't have to input every time they go on the app?)
Many thanks.

Related

Get country name of iOS user without using location

I need to get the exact country location of the user without using location permissions.
I have tried using locale, but it can be changed manually by user.
let loc = Locale.current
print(loc.regionCode)
Right now i am getting location using locale, but it can be changed by the user manually. I need to check the exact country of the user.
There are web API services your app could contact to obtain the rough location of the ip address. It's not at all guaranteed to be the correct country of the device, as your user may be using an out-of-country VPN service, but it's probably the only thing you can do without asking the device for location.
Here's an example service. I know nothing about the quality of this service (I picked this one at random for this answer). There seem to be many out there, so do your homework as to which would be best for your users and yourself.
There's another approach you could take: simply ask the user, and have faith that most of them will answer honestly. If their answer doesn't make sense per the timezone of the device, maybe suspect their answer is false.

Best way to get user's country?

I'm about to start expanding my secondhand app, where people can put their used university books for sale.
Right now the app is only available in one country, but in the near future other scandinavian countries will follow.
As an example I want to expand to Sweden, the user should only be able to see/buy/sell books that are for sale in that country.
I have come up with 2 solutions, but none of them are quite good:
Location decides country.
User selects the country from a list.
I would like to hear your thoughts on this, since lots of apps do this - but I can't figure out how.
Why not a combination of both? Try the location services first, if for whatever reason they have location services turned off or don't allow it, have them select their country. The country selection should be one of the first prompts they are given when they open the app (if location services aren't on). Otherwise, before they are allowed to post any books for sale. In other words they shouldn't be allowed to put a book up for sales without the app knowing which country they are in.
Are you using swift (what version) or objective-c?
https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/
You'll need a list of countries: How do I get a list of countries in Swift ios?
If you are willing to pay some. You could look at a ip based Solution like the www.maxmind.com api. It Gives country info and more. And we bought 50.000 queries for 50 dollars. And as we check once per user, we did not even finísh our bought queries!
I believe your application should do a guesswork and provide easy-to-use alternative for the case when the guess was incorrect. Get the country by location or IP. When the user installs the app, show the selected country and make sure your user can easily change it both in the installer and in the app itself (if, for instance, one student moves from a country to the other).

How to get user's age category inside an iOS app?

The Apple App Store has some fairly strict requirements on what content an app can display and still meet the age ratings. I'd like to add a feature that can display content created by any 3rd party which means that, though "adult content" is not appropriate, it's not possible to guarantee that some spammer or vulgar person doesn't post inappropriate things.
I'm considering blocking access to that particular feature of the program for younger users.
How can an iOS app determine the age "category" of its user in order to choose what features to provide?
Other suggestions on how to deal with the issue of un-vetted 3rd party content is also welcome.
Ok so basically you want to know if there is a way to detect the users age and thus display certain features as is appropriate.
Well two ideas come to mind:
IDEA 1
You could try using the built in contacts API to see which contact the user has set themself as. If they have one, then check if it has a birth date. And thus figure out their age.
IDEA 2
Ask the user to enter their birth date in when they launch the app for the very first time. Then figure out the age and save it in a NSUserDefault. You can then use that value throughout the app to determine what features and posts to show the user.

How to get time adjusted to user timezone in Sitecore CMS

I'm using custom command to import data for newly created item in Sitecore. Since there is a lot of data importing, this process is in the background. I send an email with import status once it is completed. I am able to get email from UserProfile:
User currentUser = Sitecore.Context.User;
UserProfile currentProfile = currentUser.Profile;
The problem is that we have import starting time in the email. Since I haven't find where the user time zone is stored, I can't adjust it to match the user time zone.
Do you happen to know if there is any setting to define user time zone from the C# code?
P.S. In the bottom right corner there is a correct time adjusted for the current user, but I didn't find any information on how and where it stored
I'm not sure it's stored (in fact I believe Sitecore stores DateTime relative to the CM server and not the client).
For you to have an accurate timezone for the visitor/customer, you'd need to either ask for it directly (registration prompt or user profile option) or look it up using Geo data from the originating ip (though with VPNs and public access points this becomes increasingly less reliable).
My suggestion would be to store the start time in UTC and (if necessary) let the user know it was started at that time. If a time elapsed is required, perform the calculation before sending the email off--since start time and end time are relative to the server anyways, just let them know it took "5min 30sec" to complete. If they receive the email at 5:08pm (email timestamp) they can do some simple match and assume it was started at 5:03 (or thereabouts).
I believe the time in the bottom right of the Desktop is using the users local system time (most likely using JavaScript) so it is not dependent on their Sitecore user profile.
There doesn't appear to be any timezone information stored against the user profile, the best you can get the is the CultureInfo based on the Regional ISO Code, although this still is not truly accurate for countries with multiple timezones (USA, Canada, Russia, Australia etc).
You could extend the User Profile to add custom properties and store a timezone field, but it is not available by default.
My suggestion would be to list the start time in UTC time, and let the user mentally adjust to their own timezone. This is what I have done previously, esp since servers themselves could be located in any location.

How to get the user's current city name without using the core location service?

So the original requirements was that on the launch of the app, the mobile app will get the current location of the user precise to City. Based on the city, the server/app client will give-city related content.
I know it would not be too difficult if I could use the core location service (since you know suspicious (self-concerned) users usually will disable the location service for a not-so-trusting app).
I have searched the web for few hours and get an summary of following solutions where I need your help to decide which one could be my best option or if you have any other better ones.
Using the [NSlocale autoupdatingCurrentLocale]
cons:
a.The explanation of the return value of the call from apple's document: "The locale is formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences." From which I don't understand what is "custom settings the user has specified in System Preferences"
reference link
b. This value could be misleading and not related with user's actual current city/country at all.
comments: I would be appreciated if anybody could explain me how the locale is changed according to user's setting.
Getting the current iPhone TimeZone
NSTimeZone *localTime = [NSTimeZone systemTimeZone];
NSLog(#"Current local timezone is %#",[localTime name]);
cons:
a. same as item b above, because user can always specify rather than let the system auto update the time zone.
b. precision is comprimised, only capital city will be listed.
comments:Not very promising but easy to implement
Using IP based location detection webservice
Based on my reading, the process will involve the app sending a request to a server where the server will record the IP of the request.(Don't think from App itself could get its own IP correctly since it may inside a local network) Based on the IP recorded through some third party service (with a IP db or some other available APIs), it will return the city information back to the client.
cons:
a. I've never implemented such thing, don't know if it is feasible for a mobile app.
b. Even if it is possible, don't know if it is faster than the core location service.
comments: If you know it is possible for a iOS app to do so please let me know.
Please kindly give me any thoughts you have or suggest any better solution if you know.
Thank you very much.
A preventive measure to avoid all your trouble would be to create an app that wouldn't appear 'not-so-trusting' and use core location to get the location. If a user still does not allow your app to know the location and knowing his city is a must, let him select a city from the list of cites for which content is available. Of course this opens up a huge hole allowing use to get the content for ANY city. Only you can decide if this is an acceptable tradeoff for simpler implementation.
If you must know the CITY automatically without core location, the first two options you mentioned, 'locale' and 'time zone' are useless as each of them encompasses large number of cities. Also, as you mentioned they're dependent on user's settings.
So reverse geocoding the IP address of a web service request using GeoIP or some such service is your best bet. You can find a lot of discussion and references for this on the web.
NSlocale can be highly inaccurate. My colleague bought the iPhone from New Zealand (he was studying there). When I am testing his phone to get the locale for language, it still show as New Zealand English.
Using IP is possible. I made a quick search and I found:-
Find IP address in iphone
how to get ip address of iphone programmatically
You might want to take a good read from above links.
I still think using Core Location is the best way to get the location of the user.

Resources