Swift / iOS 12+
you can try it via the CoreTelephony
framework, eg.
let noAvailability = CTTelephonyNetworkInfo()
.serviceSubscriberCellularProviders?
.values
.compactMap { $0.mobileCountryCode }
.isEmpty ?? false
The official docs of mobileCountryCode
(of CTCarrier
) contains a bit more information about some edge cases, which may be worth to take into account.
original answer
try to link the CoreTelephony.framework
then:
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
NSString *_code = [[[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider] mobileCountryCode];
you can find more information in the official documentation about that but briefly:
The value for this property is nil
if any of the following applies:
The value may be nil
on hardware prior to iPhone 4S when in Airplane mode.