Last active
November 3, 2019 09:00
-
-
Save PH9/f6ebd33dab13b903d835bdfd9a70d7d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// 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