views:

169

answers:

4

I'd like to be able to determine which store the user connects to from inside my app, so that I can direct them to some appropriate content for their device AND store. Does anyone know how to get this information?

Basically, if the user is in the UK, and connects to the UK store, I want my function/method to return GB, if in Korea, I want KR, Australia = AU etc. Any help would be appreciated.

A: 

A hard way to get this function is to set up up a single app for every app store country. Each app holds it's own country store information. This assumes, that a user sticks to one store, which should be true for most people.

Not really the type of solution I'm looking for, although, in a bind, I'll do that. I'm sure there's an easier way, I just don't know what it is.
pms1969
A: 

You should probably use

[[userDefaults dictionaryRepresentation] objectForKey:@"NSLocaleCode"];

This will return a language code like en_US or en_UK or en_AU or even zh_CN, zh_MY, jp_JP and so on.

Parse the correct codes which you support and direct them accordingly.

Mugunth Kumar
Thanks Mugunth, but locale and store don't necessarily equate to the same thing. I need an elegant way to figure out the store that the user is directed to. I.E. on what store do they spend their money.Don't suppose there's a userdefaults for NSAppStore?
pms1969
A: 

I suggest you try iTunes deep links. For example, http://itunes.com/apps/appname should take the user to the local App Store where she spends money.

Costique
ok, but how do I detect what the store is. So for instance I could display something like "Your App Store is ..."
pms1969
+1  A: 

I need the same functionality. At the moment I'm considering reading using data from NSLocale as default, but adding a setting in settings.app for user to customise this if it does not match.

This function is taken from an answer to another question of mine.

- (NSString *)getUserCountry
{
    NSLocale *locale = [NSLocale currentLocale];
    return [locale objectForKey: NSLocaleCountryCode];
}
prendio2
Thought of the setting too. But I don't particularly like that as an idea, as for instance, you have a lot of naturally spanish speaking people in the states, who's locale may be completely different from the store they use. I think I'm close to an answer of myself, and I'll post if it works out.
pms1969
I thought this answer to one of my questions might be of interest: http://stackoverflow.com/questions/2639684/itunes-music-store-link-maker-how-to-search-from-within-my-app/2668190#2668190wouldn't ThierryB's `getUserCountry` method return US for users in US regardless of what their language was set to?
prendio2
Thanks, I tried that early on, but it didn't work the way I expected, or returned an incorrect result. Having said that, I can't actually remember having done it on the phone (had done in simulator), so I'll have a play when I sort out my damn provisioning profile and can debug on the phone again.
pms1969
OK, seems to have worked (getUserCountry), so giving this the thumbs up. The problem with it of course is if someone (say a Brit) lives the expat life in somewhere like Australia, and has the country code set to GB even tho their store is AU. But unless I can come up with a better method, this will have to do, coupled with an option to change the store.
pms1969
cheers… I've added the relevant code to the answer
prendio2