Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Knowing app store country

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 !

like image 531
Melanie Journe Avatar asked Mar 19 '18 17:03

Melanie Journe


3 Answers

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.

like image 68
bandejapaisa Avatar answered Nov 19 '22 08:11

bandejapaisa


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.

like image 28
oroom Avatar answered Nov 19 '22 09:11

oroom


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
}
like image 4
D. Franco Avatar answered Nov 19 '22 10:11

D. Franco