iphone獲取sim卡信息
/*
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;
} 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!