IPhone - SIM Accessibility Detection

I am using the answer in this section. iPhone - how to identify the device’s media (AT&T, Verizon, etc.) , which is the same as getting operator details on the iphone . Although it works great when using a SIM card, the name of the returned airline, if there is no SIM card, is the old name of the operator. It does not detect that the SIM card is removed.

I know that this contradicts Apple documentation, that if there is no carrier, the CTCarrier object must be zero. But in my application I registered information about the carrier, and it gives me the last name of the operator, although the simulator is not installed.

+6
source share
4 answers

According to the documentation for [CTCarrier carrierName] :

If you configure the device for media and then remove the SIM card, this property saves the media name.

As far as I know, you cannot determine if a SIM card is installed. You can determine if a WWAN connection is available using Reachability .

+7
source
 @import CoreTelephony; -(BOOL)hasCellularCoverage { CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new]; CTCarrier *carrier = [networkInfo subscriberCellularProvider]; if (!carrier.isoCountryCode) { NSLog(@"No sim present Or No cellular coverage or phone is on airplane mode."); return NO; } return YES; } 
+7
source

The CTCarrier object has 5 properties:

 allowsVOIP carrierName isoCountryCode mobileCountryCode mobileNetworkCode 

I did some tests regarding CTCarrier, and I came to the conclusion that for iOS 7 only port_name and allows VOIP to be saved when the SIM card is removed. isoCountryCode, mobileCountryCode and mobileNetworkCode are reset for iOS 7. How can you determine if a SIM card is present or not.

For iOS 6, all values ​​are saved.

I performed the tests using the iPhone 4S and iPhone 5 running iOS 7.

+4
source

Quick version:

 func hasCellularCoverage() -> Bool { let networkInfo = CTTelephonyNetworkInfo() guard let info = networkInfo.subscriberCellularProvider else {return false} if let carrier = info.isoCountryCode { print("No sim present Or No cellular coverage or phone is on airplane mode. Carrier = \(carrier)"); return true } return false } 

or

 func hasCellularCoverage() -> Bool { let networkInfo = CTTelephonyNetworkInfo() guard let info = networkInfo.subscriberCellularProvider else {return false} return info.isoCountryCode != nil ? true : false } 
0
source

Source: https://habr.com/ru/post/915127/


All Articles