13

I'm trying to make a list carrier with subscriberCellularProvider. But I got one problem which is "'subscriberCellularProvider' was deprecated in iOS 12.0: Replaced by serviceSubscriberCellularProviders"

I'm using XCode 11.4.1 and iOS 13. Anybody can help me to solve this problem?

Vikram Parimi
  • 777
  • 6
  • 29
Hanan Hakim
  • 131
  • 1
  • 3

3 Answers3

14

The warning is telling you that you should use CTTelephonyNetworkInfo().serviceSubscriberCellularProviders instead, that returns an optional dictionary of type [String : CTCarrier]?. Probably is added to support devices with multiple sim (eg. iPhone XR with SIM + eSIM)

I can't figure out which key to use with the dictionary, in my case (iPhone 8) I have only one object with key 0000000100000001 so I get the carrier with:

CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?["0000000100000001"]

You could try with:

CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.first?.value

but obviously there’s not guarantee that you will get the same info between different executions of your app.

I couldn't find any further documentation about it

Andr3a88
  • 679
  • 5
  • 13
6

'subscriberCellularProvider' is deprecated: first deprecated in iOS 12.0 Replace 'subscriberCellularProvider' with 'serviceSubscriberCellularProviders'

#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>


CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];

NSDictionary<NSString *, CTCarrier *> *providers= [networkInfo serviceSubscriberCellularProviders];
                
CTCarrier *carrier = providers.allValues.firstObject;
                
NSString* isoCountryCode = carrier.isoCountryCode;
                
NSString* mobileNetworkCode = carrier.mobileNetworkCode;
                
NSString* mobileCountryCode = carrier.mobileCountryCode;
                
NSString* carrierName = carrier.carrierName;
            
Haseeb Javed
  • 61
  • 1
  • 4
  • 5
    Before you paste this in even more locations, please take the time to read [Is it acceptable to add a duplicate answer to several questions?](https://meta.stackexchange.com/questions/104227/is-it-acceptable-to-add-a-duplicate-answer-to-several-questions). – fcdt Oct 14 '20 at 13:22
  • Is this a solution you never explained where to write this? – Rehan Ali Khan Oct 03 '21 at 18:51
  • @RehanAliKhan this solution is relevant to the above question asked. I didn't get the point? Please elaborate. – Haseeb Javed Oct 04 '21 at 09:41
4

@Andr3a88 's answer is not precise. For iPhone with 2 SIM cards CTTelephonyNetworkInfo().serviceSubscriberCellularProviders returns at least 2 elements one of them may have carrier as this

CTCarrier (0x283d8e940) {
    Carrier name: [<nil>]
    Mobile Country Code: [<nil>]
    Mobile Network Code:[<nil>]
    ISO Country Code:[<nil>]
    Allows VOIP? [YES]

for non-used eSIM I guess.

So it is preferable to check if carrier name is not NIL

let netInfo = CTTelephonyNetworkInfo()
let carrier = netInfo.serviceSubscriberCellularProviders?.filter({ $0.value.carrierName != nil }).first?.value
Alexey Ishkov
  • 399
  • 4
  • 4