Skip to content

Instantly share code, notes, and snippets.

@PH9
Last active November 3, 2019 09:00
Show Gist options
  • Save PH9/f6ebd33dab13b903d835bdfd9a70d7d4 to your computer and use it in GitHub Desktop.
Save PH9/f6ebd33dab13b903d835bdfd9a70d7d4 to your computer and use it in GitHub Desktop.
import CoreTelephony
// Under iOS 12
func isThailandOperator() -> Bool {
let networkInfo = CTTelephonyNetworkInfo()
guard let carrier = networkInfo.subscriberCellularProvider else {
return false
}
guard let mcc = carrier.mobileCountryCode else {
throw ReachabilityError.cannotGetMobileCountryCode
}
// 520 is Thailand
guard mcc == "520" else {
throw ReachabilityError.countryCodeIsNotThailand
}
guard let mnc = carrier.mobileNetworkCode else {
throw ReachabilityError.cannotGetMobileNetwork
}
let networkList = [
"00": "TruemoveH",
"03": "AIS",
"05": "dtac",
]
return networkList.contains(where: { key, _ -> Bool in
return key == mnc
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment