Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Detecting SIM card availability

I am using the answer in this topic. iPhone - how to determine carrier of the device (AT&T, Verizon, etc?) which is the same as getting operator details in iphone. Although it works fine when using a sim card, the returned carrier name if there is no SIM card is the old carrier name. It doesn't detect that the SIM is removed.

I know this contradicts with Apple documentation that if there is no carrier, CTCarrier object shall be nil. But in my app I logged the carrier info and it gives me the latest carrier name although no sim is installed.

like image 897
Abdalrahman Shatou Avatar asked May 07 '12 20:05

Abdalrahman Shatou


2 Answers

hope this helps:

    if #available(iOS 12.0, *) {
        return CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.first?.value.mobileNetworkCode != nil
    } else {
        if let _ = CTTelephonyNetworkInfo().subscriberCellularProvider?.isoCountryCode {
            return true
        } else {
            return false
        }
    }
like image 144
horn Avatar answered Oct 24 '22 01:10

horn


According to the documentation for [CTCarrier carrierName]:

If you configure a device for a carrier and then remove the SIM card, this property retains the name of the carrier.

As far as I know, you cannot detect if the SIM card is installed. You can only determine if a WWAN connection is available using Reachability.

like image 33
Evan Mulawski Avatar answered Oct 24 '22 01:10

Evan Mulawski