18

I am trying to create an ios application and I want to segment the users based on the data providers they are using, such as Verizon and AT&T. Is it possible to get this information programmatically from the ios application.

Cœur
  • 32,421
  • 21
  • 173
  • 232
auditya
  • 359
  • 1
  • 4
  • 10

3 Answers3

49

You should check the CTCarrier.

Just import CoreTelephony into your Swift file.

Then you can use the carrierName property to get the name of your carrier.

// Setup the Network Info and create a CTCarrier object
let networkInfo = CTTelephonyNetworkInfo()
let carrier = networkInfo.subscriberCellularProvider

// Get carrier name
let carrierName = carrier.carrierName
eyeballz
  • 882
  • 9
  • 26
Christian
  • 21,440
  • 9
  • 77
  • 100
  • It is the SIM card's operator name, is not unnecessary the current network's operator in using. – DàChún Oct 12 '17 at 09:58
  • 'subscriberCellularProvider' was deprecated in iOS 12.0: Replaced by serviceSubscriberCellularProviders – Famic Tech Oct 14 '18 at 15:46
  • 9
    For iOS 12, given the ability to have multiple SIM cards in some devices, Apple has depreciated 'subscriberCellularProvider' and replaced it with an array of cellularProviders, 'serviceSubscriberCellularProviders'. If unconcerned with CTCarrier selected, just use: `let carrier = networkInfo.serviceSubscriberCellularProviders?.first?.value` – Ever Uribe Mar 26 '19 at 23:32
  • 1
    it just prints "Carrier" for me ;/ – Jafar Khoshtabiat Oct 17 '19 at 13:00
3

You will want to use the CTCarrier carrierName in the CoreTelephony framework: https://developer.apple.com/library/prerelease/ios/documentation/NetworkingInternet/Reference/CTCarrier/index.html#//apple_ref/occ/instp/CTCarrier/carrierName

Gary Riches
  • 2,729
  • 1
  • 20
  • 17
2

Now that you can have multiple SIM cards, subscriberCellularProvider is deprecated in favor of serviceSubscriberCellularProviders. You can get an array of the providers with this:

CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.values

In my case, I was checking to see if the user has an American phone number so they can text support instead of email. You can do that with this:

carriers.contains { $0.isoCountryCode?.lowercased() == "us" }

On my phone, I only have one SIM card, but this array returns two values and one has all nil properties so be sure to handle that if you are inspecting them.

Sam Soffes
  • 14,138
  • 9
  • 68
  • 78