iOS iTunes store country

北城余情 提交于 2019-12-04 22:34:39

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);

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!