/*
iphone擷取sim卡資訊
1.加入一個Framework(CoreTelephony.framework).
2.引入標頭檔
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
3.初始化
*/
//-----------------------------------
具體demo
//-----------------------------------
#import <UIKit/UIKit.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
@interface RootViewController : UITableViewController
{
//聲明變數
CTTelephonyNetworkInfo *networkInfo;
}
@end
@implementation RootViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.prompt = @"CTTelephonyNetworkInfo";
self.navigationItem.title = @"CTCarrier";
//初始化
networkInfo = [[CTTelephonyNetworkInfo alloc] init];
//當sim卡更換時彈出此視窗
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
{
//擷取sim卡資訊
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://供應商名稱(中國聯通 中國移動)
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;
}
return cell;
}