iOS iTunes store country
Asked Answered
C

4

19

i am wondering if there is a solution to find out, in which country the user downloaded an application.

For example: app x has been downloaded in USA when the user opens up the app, the app will check in which country it was downloaded. In this example the the return would be "USA"

Does any one hase an idea on how to solve this?

Clubman answered 26/7, 2012 at 13:24 Comment(0)
S
10

If you have any In-App Purchases available, you can read the locale from the SKProduct. As a fallback, use the device's locale.

NSLocale *locale;
SKProduct *baseProduct = nil; // replace as applicable
if (baseProduct) {
    locale = baseProduct.priceLocale; // from the user's credit card on iTunes
} else {
    locale = [NSLocale currentLocale]; // from user preferences
}
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
NSLog(@"Two-letter country code: %@", countryCode);
Sathrum answered 9/12, 2013 at 6:34 Comment(1)
I think we can just use [NSLocale currentLocale].countryCode.Cosmo
B
3

There might be a good enough correlation between the iTunes store country and the locale a user sets. This depends on your needs - if this does not suffice, I don't think there is a way to know which actual store an app was downloaded from.

To retrieve that locale, you could use:

NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];

Hope this is sufficient for your needs.

Blus answered 26/7, 2012 at 13:31 Comment(0)
B
0

It's not possible to check "which" App Store an app was downloaded.

If you need to do anything location-based, you should look at CLLocation to obtain a user's current location, however it may seem intrusive for the app to ask a user for their location if it's not apparent why it would need the location.

You could also check for the language on a users device, such as en_gb for Britain, dk for Denmark, en_ca for Canada, etc. While this doesn't completely cover when people in some countries have set the language to something else than the countries native language, it's better than nothing.

Breunig answered 26/7, 2012 at 13:29 Comment(0)
A
0

SKStoreFront, introduced in iOS 13 SDK seems to do the job.

Swift

if let storefront = SKPaymentQueue.default().storefront {
    print(storefront.countryCode) // Returns an Alpha-3 country code (USA, GBR etc.)
}

Obj C

[SKPaymentQueue defaultQueue].storefront.countryCode; // Returns an Alpha-3 country code (USA, GBR etc.)

You should be able to access the SKStoreFront instance by adding the StoreKit framework to your project, even if your app does not offer any purchases.

Anorexia answered 28/8, 2020 at 8:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.