IPhone之获取Sim卡信息

原文地址:IPhone之获取Sim卡信息 作者:飞舞的鸡毛

首先,加入一个Framework.



引入头文件

#import <UIKit/UIKit.h>

#import<CoreTelephony/CTTelephonyNetworkInfo.h>

#import<CoreTelephony/CTCarrier.h>
@interface RootViewController : UITableViewController

{

    CTTelephonyNetworkInfo *networkInfo;

}

 

 

初始化

- (void)viewDidLoad

{

    [superviewDidLoad];
    self.navigationItem.prompt = @"CTTelephonyNetworkInfo";

   self.navigationItem.title = @"CTCarrier";
   networkInfo = [[[CTTelephonyNetworkInfo alloc] init] retain];
   //当sim卡更换时弹出此窗口

  networkInfo.subscriberCellularProviderDidUpdateNotifier = ^(CTCarrier * carrier)

  {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nilmessage:@"Sim card changed"     delegate:nilcancelButtonTitle:@"Dismiss" otherButtonTitles:nil];

   [alert show];

   [alert release];

  };

}

 

获取Sim卡信息

CTCarrier *carrier = networkInfo.subscriberCellularProvider;
switch (indexPath.row)

{

case 0://供应商名称(中国联通 中国移动)

cell.textLabel.text = @"carrierName";

cell.detailTextLabel.text = carrier.carrierName;

break;

case 1://所在国家编号

cell.textLabel.text = @"mobileCountryCode";

cell.detailTextLabel.text = carrier.mobileCountryCode;

break;

case 2://供应商网络编号

cell.textLabel.text = @"mobileNetworkCode";

cell.detailTextLabel.text = carrier.mobileNetworkCode;

break;

case 3:

cell.textLabel.text = @"isoCountryCode";

cell.detailTextLabel.text = carrier.isoCountryCode;

break;

case 4://是否允许voip

cell.textLabel.text = @"allowsVOIP";

cell.detailTextLabel.text = carrier.allowsVOIP?@"YES":@"NO";

break;

default:

break;

}

 

 


你可能感兴趣的:(网络,iPhone,中国移动,interface)