Skip to content

Instantly share code, notes, and snippets.

@petermolnar-dev
Created May 6, 2022 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermolnar-dev/a9d69d2809adb7807aaa4d8109317f80 to your computer and use it in GitHub Desktop.
Save petermolnar-dev/a9d69d2809adb7807aaa4d8109317f80 to your computer and use it in GitHub Desktop.
CountryDetector_With_Locale_fallback
import CoreTelephony
class CountryDetector {
var telephonyInfo = CTTelephonyNetworkInfo()
func detectCountryWithoutLocation() -> String? {
guard let provider = telephonyInfo.serviceSubscriberCellularProviders?.first(where: { $0.value.isoCountryCode != nil })?.value else {
return Locale.current.regionCode
}
return provider.isoCountryCode
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment