原文 和 代码下载地址:http://blog.csdn.net/diyagoanyhacker/article/details/6582783
+ (NSString*)getCarrier:(NSString*)imsi
{if (imsi == nil || [imsi isEqualToString:@"SIM Not Inserted"] ) {
return @"Unknown";
}
else {
if ([[imsi substringWithRange:NSMakeRange(0, 3)] isEqualToString:@"460"]) {
NSInteger MNC = [[imsi substringWithRange:NSMakeRange(3, 2)] intValue];
switch (MNC) {
case 00:
case 02:
case 07:
return @"China Mobile";
break;
case 01:
case 06:
return @"China Unicom";
break;
case 03:
case 05:
return @"China Telecom";
break;
case 20:
return @"China Tietong";
break;
default:
break;
}
}
}
return @"Unknown";
}
须引入头文件
#import "UIDevice-IOKitExtensions.h"
#include <sys/types.h>
#include <sys/sysctl.h>
#import <mach/mach_host.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <ifaddrs.h>