使用Objective-C获取IPHONE手机IMSI序列号
更新时间:2015年04月01日 09:23:21 投稿:hebedich
这篇文章主要介绍了使用Objective-C获取IPHONE手机IMSI序列号的方法以及通过IMSI序列号获取运营商、手机号的方法,非常的实用,有需要的小伙伴可以参考下。
获取IPhone 的IMSI序列号
#include <dlfcn.h>
#define PRIVATE_PATH "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
- void getImsi(){
#if !TARGET_IPHONE_SIMULATOR
void *kit = dlopen(PRIVATE_PATH,RTLD_LAZY);
NSString *imsi = nil;
int (*CTSIMSupportCopyMobileSubscriberIdentity)() = dlsym(kit, "CTSIMSupportCopyMobileSubscriberIdentity");
imsi = (NSString*)CTSIMSupportCopyMobileSubscriberIdentity(nil);
dlclose(kit);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"IMSI"
message:imsi
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
#endif
}
通过IMSI获取运营商
NSString *imsi = CTSIMSupportCopyMobileSubscriberIdentity();
NSString *userMobileType = [StatisticsOperation getCarrier:imsi];
getCarrier 方法如下
+ (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";
}
获取手机号
+ (NSString*)getPhoneNumber
{
NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"];
NSLog(@"Phone Number: %@", num);
return num;
}
以上所述就是本文的全部内容了,希望大家能够喜欢。
您可能感兴趣的文章:
- 在一个项目中同时使用Swift和Objective-C代码混合编程的方法
- objective-c中生成随机数的方法
- Swift调用Objective-C编写的API实例
- Objective-C 消息传递机制详解
- Objective-c代码如何移植为Swift代码 Objective-c代码转移到Swift过程介绍
- Objective-C中NSArray的基本用法示例
- Swift能代替Objective-C吗?
- 在Swift中使用Objective-C编写类、继承Objective-C类
- 全面解析Objective-C中的block代码块的使用
- Objective-C中NSLog输出格式大全
- Swift调用Objective-C代码
- Objective-C中的重载和重写详解


最新评论