我试图从设备SIM运营商获得mobileCountryCode.
我从mobileCountryCode得到的结果是6553565535
,应该是US
或FR
下面是我Objective-C代码
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = nil;
// The CTTelephonyNetworkInfo.serviceSubscriberCellularProviders method crash because of an issue in iOS 12.0
// It was fixed in iOS 12.1
if (@available(iOS 12, *)) {
NSDictionary<NSString *, CTCarrier *> *carriers = nil;
if (@available(iOS 12.1, *)) {
carriers = [networkInfo serviceSubscriberCellularProviders];
} else {
carriers = [networkInfo valueForKey:@"serviceSubscriberCellularProvider"];
}
if (carriers != nil) {
for (NSString *key in carriers) {
carrier = carriers[key];
NSLog(@"isoCountryCode : %@", carrier.isoCountryCode.description);
}
}
} else {
carrier = [networkInfo subscriberCellularProvider];
}
NSString *codeInfo = @"";
if (carrier != nil && carrier.mobileCountryCode != nil) {
codeInfo = [carrier.mobileCountryCode stringByAppendingString:carrier.mobileNetworkCode];
}
NSLog(@"countryCode: %@", codeInfo.description);
打印我们的结果:
Carrier name: [--]
Mobile Country Code: [65535]
Mobile Network Code:[65535]
ISO Country Code:[--]
Allows VOIP? [YES]
我错过了什么吗?
我使用的是xCode 14.3
1条答案
按热度按时间tez616oj1#
serviceSubscriberCellularProvider在iOS 16中被弃用,XCode 14.3随iOS 16一起提供。https://developer.apple.com/documentation/coretelephony/cttelephonynetworkinfo/3024511-servicesubscribercellularprovide