Reputation: 105
I'm making use of the following code to obtain the mobileNetworkCode
:
let ctCarrier = CTCarrier()
func getMNC() -> String {
if let mnc = ctCarrier.mobileNetworkCode {
return mnc
}
return "nil"
}
Using any properties of CTCarrier returns nil and seems like a bug from Apple.
Any workaround as to this problem?
Upvotes: 3
Views: 1013
Reputation: 55
let networkInfo = CTTelephonyNetworkInfo()
let carrier = networkInfo.subscriberCellularProvider
let mobileNetworkCode = carrier!.mobileNetworkCode
if mobileNetworkCode != nil {
//Means got reception
} else {
//No cellular data
}
Please try this way, i also test using CTCarrier()
directly, it always returns nil. This method works.
Upvotes: 3
Reputation: 13290
Make sure you have the following:
Discussion on mobileNetworkCode:
A read-only NSString object that represents the numeric mobile network code for the user’s cellular service provider. Typing this property as an NSString object, rather than a number type, ensures that leading zeroes in MNCs are respected.
Reference: https://developer.apple.com/documentation/coretelephony/ctcarrier/1620324-mobilenetworkcode
Upvotes: 0