11

I haven't found a thread about this so I must ask: is there a way to programmatically detect which app store the app was downloaded from? (ie: Germany App Store)

I don't want to have to ask for location privileges to detect user location but if there isn't a way to detect the app store then I may have to.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Silverstar
  • 463
  • 1
  • 5
  • 13
  • 1
    Have you found a better solution? Because people might not set the Locale to their country of residence, but more like their preference. – Van Du Tran Nov 15 '16 at 04:45

3 Answers3

11

If you have In App Purchases you can check the priceLocale of your SKProduct, which gives you the store (currency and country) the user currently is logged in.

Apple recommended this at WWDC2014 Session 303 Optimizing In-App Purchases at 10:30.

JeanLuc
  • 4,783
  • 1
  • 33
  • 47
4

I think you'd use the current locale of the user to detect in which country they are… but it could fail sometimes, so I'm not very sure if a not 100% effective way to detect the AppStore would work for you.

You'd need to call

[[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]

Also, please see discussions in the following threads, some of them are old, but probably will help you to find alternatives solutions too Link1 and Link2

Community
  • 1
  • 1
Barbara R
  • 1,057
  • 5
  • 18
  • @OnesAndZeros great to know it was helpful! could you accept my answer as valid ? Thanks! – Barbara R Apr 26 '14 at 00:38
  • its often the same, but not always. you are returning the system language settings but not the app store county settings. they don't have to match – user1259710 May 29 '18 at 21:41
  • this is not the proper solution. you are checking the system language settings and not the app store country settings. they often match, but not always. there are many users that use another store for various reasons (e.g. to obtain content thats not available in their local store). – user1259710 May 29 '18 at 21:43
  • Sorry, downvoting because it's not a solution for the given question. The region/country code might differ from the App Store. In my case, they are Italy and Germany. AFAIK, there is no way of detecting the App Store Region. – Zeb Jun 03 '19 at 10:03
1

the NSLocale answer is wrong as the system language settings don't have to match the app store country. some users buy in foreign stores because more content is available. using StoreKit/SKProduct probably works, but is available only for apps distributed in the store.

if you are on the Mac, you can just parse a config file of the Mac App Store directly as done here: https://github.com/core-code/CoreLib/blob/master/Mac/JMHostInformation.m in the "appStoreCountryCode" method

user1259710
  • 868
  • 2
  • 9
  • 12