/*
Iphone SIM card information
1. Add a Framework (CoreTelephony. framework ).
2. Introduce the header file
# Import <CoreTelephony/CTTelephonyNetworkInfo. h>
# Import <CoreTelephony/CTCarrier. h>
3. Initialization
*/
//-----------------------------------
Demo
//-----------------------------------
# Import <UIKit/UIKit. h>
# Import <CoreTelephony/CTTelephonyNetworkInfo. h>
# Import <CoreTelephony/CTCarrier. h>
@ Interface RootViewController: UITableViewController
{
// Declare Variables
CTTelephonyNetworkInfo * networkInfo;
}
@ End
@ Implementation RootViewController
-(Void) viewDidLoad
{
[Super viewDidLoad];
Self. navigationItem. prompt = @ "CTTelephonyNetworkInfo ";
Self. navigationItem. title = @ "CTCarrier ";
// Initialization
NetworkInfo = [[CTTelephonyNetworkInfo alloc] init];
// This window is displayed when the SIM card is changed
NetworkInfo. subscriberCellularProviderDidUpdateNotifier = ^ (CTCarrier * carrier ){
UIAlertView * alert = [[UIAlertView alloc] initWithTitle: nil message: @ "Sim card changed" delegate: nil cancelButtonTitle: @ "Dismiss" otherButtonTitles: nil];
[Alert show];
};
}
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath
{
// Obtain SIM card information
CTCarrier * carrier = networkInfo. subscriberCellularProvider;
Static NSString * CellIdentifier = @ "Cell ";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
If (cell = nil ){
Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: CellIdentifier];
}
Switch (indexPath. row ){
Case 0: // Supplier name (China Unicom China Mobile)
Cell. textLabel. text = @ "carrierName ";
Cell. detailTextLabel. text = carrier. carrierName;
Break;
Case 1: // country ID
Cell. textLabel. text = @ "mobileCountryCode ";
Cell. detailTextLabel. text = carrier. mobileCountryCode;
Break;
Case 2: // supplier network ID
Cell. textLabel. text = @ "mobileNetworkCode ";
Cell. detailTextLabel. text = carrier. deleenetworkcode;
Break;
Case 3:
Cell. textLabel. text = @ "isoCountryCode ";
Cell. detailTextLabel. text = carrier. isoCountryCode;
Break;
Case 4: // whether voip is allowed
Cell. textLabel. text = @ "allowsVOIP ";
Cell. detailTextLabel. text = carrier. allowsVOIP? @ "YES": @ "NO ";
Break;
Default:
Break;
}
Return cell;
}