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 !
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.
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
.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With