Created
May 6, 2022 14:57
-
-
Save petermolnar-dev/a9d69d2809adb7807aaa4d8109317f80 to your computer and use it in GitHub Desktop.
CountryDetector_With_Locale_fallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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