Help with "serviceSubscriberCellularProviders"

Hey, I've got a source code in XCode which looks like that:

#if !(TARGET_IPHONE_SIMULATOR)   NSString *carrierName = nil;   CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];   if (netinfo) {     CTCarrier *carrier = netinfo.serviceSubscriberCellularProviders;     carrierName = carrier.carrierName;   }   if (carrierName) {     info[@"carrierName"] = carrierName;   } #endif       return info; }

@end

Now I get a warning: "Incompatible pointer types initializing 'CTCarrier *' with an expression of type 'NSDictionary<NSString *,CTCarrier *> * _Nullable'"

What does that mean?

Next time, please make sure to use code block formatting like this:

CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = netinfo.serviceSubscriberCellularProviders;

The error message should lead you to checking the documentation for serviceSubscriberCellularProviders which is indeed a dictionary containing CTCarrier objects rather than a single CTCarrier object. This supports phones with multiple SIMs. There’s an older (and deprecated) subscriberCellularProvider property that hold a single CTCarrier object but the documentation doesn’t define its behavior when there are multiple SIMs, so it’s best to use only serviceSubscriberCellularProviders.

Please see this recent thread for a detailed discussion of how to use this API, and especially note that the information in CTCarrier itself is now marked as deprecated and may become unavailable in the future. What exactly are you trying to achieve by accessing CTCarrier?

Help with "serviceSubscriberCellularProviders"
 
 
Q