16

I want to know in my app (by code) in which app store my user is (like england / france / spain ect).

I already read that we can do this with the locale : https://developer.apple.com/documentation/foundation/nslocale/1643060-countrycode

But I would like to do it with the Apple Store. For legal purpose I don't want to display the same content for an european than for an american.

Has someone already done it ? Thanks !

Melanie Journe
  • 1,249
  • 5
  • 16
  • 36
  • Did you read this? https://stackoverflow.com/questions/1112046/detect-at-runtime-which-countrys-app-store-my-iphone-app-was-downloaded-from – Maximelc Mar 19 '18 at 17:28
  • @Maximelc None of the answers to that linked question actually answer that (or this) question. – rmaddy Mar 19 '18 at 17:56
  • If your app happens to make use of in-app purchases, there is a possible solution. – rmaddy Mar 19 '18 at 17:58
  • AFAIK, you cannot get any information about the signed in user. In my personal apps I have made I also display content for the users iTunes Store. My solution was on first launch get their current locale, and save which store they should be using. I allow the user to change this setting in the app though because I could be wrong. – Maximilian Litteral Mar 19 '18 at 18:14
  • Ask the user at signup which store they use. – stevenpcurtis Mar 20 '18 at 02:30
  • Unfortunatly my app does not use in-app purchase. How could this help me ? – Melanie Journe Mar 20 '18 at 13:20
  • @rmaddy how we cna get appstore country If we are using inApp? as my application is using inAPP purchase – Moaz Saeed Oct 30 '18 at 12:36
  • @MoazSaeed I believe I was thinking of the `priceLocale` from `SKProduct` but this probably isn't really a 100% correct solution. – rmaddy Oct 30 '18 at 15:51

3 Answers3

14

From iOS13 SKStorefront class property countryCode can be used to get three-letter code representing the country associated with the App Store storefront.

For iOS version below 13 only viable solution was to get priceLocale from SKProduct.

oroom
  • 1,318
  • 11
  • 10
8

If you're on iOS 13+, This will give you the 3 letter country code for the store:

import StoreKit

let country = SKPaymentQueue.default().storefront?.countryCode

More information on it's usage can be found in the SKStoreFront documentation.

UPDATE: Occasionally, this method returns nil, which is why storefront is an optional. So it's not 100% reliable. I was using with thousands of users, and it was working 95% of the time. I'm not entirely sure under what circumstances it is nil however.

bandejapaisa
  • 26,576
  • 13
  • 94
  • 112
  • Does not work. The result is always nil. Tested with iPod touch 7th Generation 14.4 and iPhone 11 :( – Rohit Singh Sep 22 '21 at 13:39
  • 1
    I was using with thousands of users, and it was working 95% of the time. But you're right, sometimes it does return nil. I'm not sure why, nor have I investigated why. It could be due to restrictions or maybe not being logged into the app store. No idea. – bandejapaisa Sep 25 '21 at 07:49
6

You can't restrict IAP(so you don't have information about the Apple Store used) for specific country. What you can do is disable/enable items by checking country ID.

there are different way for check it, for me the best is by checking user carrier ID.

For example:

func checkCellularNumber() -> Bool {
    let networkInfo = CTTelephonyNetworkInfo()
    guard let info = networkInfo.subscriberCellularProvider else {return false}
    if let carrier = info.isoCountryCode {
        print("Carrier code = \(carrier)");
        return true
    }
    return false
}
D. Franco
  • 63
  • 1
  • 6