0

I would like to detect if the user has a SIM in their device.

There are similar questions (for example: iPhone - Detecting SIM card availability), but the suggested solutions rely on the Core Telephony framework which is now mostly deprecated.

I thought canSendText of MFMessageComposeViewController might work, but it also returns true for devices without SIM card. Probably because the user doesn't need a SIM card to use iMessage?

Does anyone know of other possibilities?

Apfelsaft
  • 5,766
  • 4
  • 28
  • 37
  • What about [this](https://developer.apple.com/documentation/coretelephony/cttelephonynetworkinfo). Part of CoreTelephony but not deprecated. – Ptit Xav Jul 30 '23 at 16:23
  • @PtitXav The class is not deprecated, but its property serviceSubscriberCellularProviders is. – Apfelsaft Jul 31 '23 at 06:07

1 Answers1

-2

If you want to detect SIM card available on device without CoreTelephony then use the CTCarrier class from the CoreTelephony framework, but without importing the entire framework:

func isSIMCardAvailable() -> Bool {
     guard let info = CTCarrier() else {
         return false
     }
     return !info.isoCountryCode.isEmpty
}
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257