大佬教程收集整理的这篇文章主要介绍了在iOS 5.1中获取CellID,MCC,MNC,LAC和网络,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在iphone,check values of cellId / Lac的问题中,作者表示我可以在iOS上收到radioId信息cellId,Lac,但是没有提供有关如何做的信息.
有人可以告诉我如何获得这个信息?
1)使用单元监视器
struct CTResult { int flag; int a; }; extern CFStringRef const kCTCellMonitorCellType; extern CFStringRef const kCTCellMonitorCellTypeserving; extern CFStringRef const kCTCellMonitorCellTypeNeighbor; extern CFStringRef const kCTCellMonitorCellId; extern CFStringRef const kCTCellMonitorLAc; extern CFStringRef const kCTCellMonitorMCc; extern CFStringRef const kCTCellMonitorMNc; extern CFStringRef const kCTCellMonitorupdateNotification; id _CTServerConnectionCreate(CfallocatorRef,void*,int*); void _CTServerConnectionAddToRunLoop(id,CFRunLoopRef,CFStringRef); #ifdef __LP64__ void _CTServerConnectionRegisterForNotification(id,CFStringRef); void _CTServerConnectionCellMonitorStart(id); void _CTServerConnectionCellMonitorStop(id); void _CTServerConnectionCellMonitorCopyCellInfo(id,CFArrayRef*); #else void _CTServerConnectionRegisterForNotification(struct CTResult*,id,CFStringRef); #define _CTServerConnectionRegisterForNotification(connection,notification) { struct CTResult res; _CTServerConnectionRegisterForNotification(&res,connection,notification); } void _CTServerConnectionCellMonitorStart(struct CTResult*,id); #define _CTServerConnectionCellMonitorStart(connection) { struct CTResult res; _CTServerConnectionCellMonitorStart(&res,connection); } void _CTServerConnectionCellMonitorStop(struct CTResult*,id); #define _CTServerConnectionCellMonitorStop(connection) { struct CTResult res; _CTServerConnectionCellMonitorStop(&res,connection); } void _CTServerConnectionCellMonitorCopyCellInfo(struct CTResult*,CFArrayRef*); #define _CTServerConnectionCellMonitorCopyCellInfo(connection,tmp,cells) { struct CTResult res; _CTServerConnectionCellMonitorCopyCellInfo(&res,cells); } #endif
…
id CTConnection = _CTServerConnectionCreate(NULL,CellMonitorCallBACk,null); _CTServerConnectionAddToRunLoop(CTConnection,CFRunLoopGetCurrent(),kcfRunLoopCommonModes); _CTServerConnectionRegisterForNotification(CTConnection,kCTCellMonitorupdateNotification); _CTServerConnectionCellMonitorStart(CTConnection); int CellMonitorCallBACk(id connection,CFStringRef String,CFDictionaryRef Dictionary,void *data) { int tmp = 0; CFArrayRef cells = NULL; _CTServerConnectionCellMonitorCopyCellInfo(connection,(void*)&tmp,&cells); if (cells == NULL) { return 0; } for (NSDictionary* cell in (NSArray*)cells) { int LAC,CID,MNc; if ([cell[(NSString*)kCTCellMonitorCellType] isEqualToString:(NSString*)kCTCellMonitorCellTypeserving]) { LAC = [cell[(NSString*)kCTCellMonitorLAC] intValue]; CID = [cell[(NSString*)kCTCellMonitorCellId] intValue]; MCC = [cell[(NSString*)kCTCellMonitorMCC] intValue]; MNC = [cell[(NSString*)kCTCellMonitorMNC] intValue]; } else if ([cell[(NSString*)kCTCellMonitorCellType] isEqualToString:(NSString*)kCTCellMonitorCellTypeNeighbor]) { } } CFRelease(cells); return 0; }
2)使用CTTelephonyCenter
kCTRegistrationCellChangedNotification每当当前的服务小区塔更改时发送.
extern CFStringRef const kCTRegistrationCellChangedNotification; extern CFStringRef const kCTRegistrationGsmLac; extern CFStringRef const kCTRegistrationLac; extern CFStringRef const kCTRegistrationGsmCellId; extern CFStringRef const kCTRegistrationCellId; CFStringRef CTSIMSupportCopymobileSubscriberCountryCode(CfallocatorRef); CFStringRef CTSIMSupportCopymobileSubscriberNetworkCode(CfallocatorRef); id CTTelephonyCenterGetDefault(); void CTTelephonyCenterAddObserver(id,void,CFNotificationCallBACk,CFStringRef,CFNotificationSuspensionBehavior);
…
CTTelephonyCenterAddObserver(CTTelephonyCenterGetDefault(),NULL,callBACk,CFNotificationSuspensionBehaviorHold); void callBACk(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object,CFDictionaryRef userInfo) { NSString* notification = (NSString*)name; NSDictionary *cellInfo = (NSDictionary*)userInfo; if ([notification isEqualToString:(NSString*)kCTRegistrationCellChangedNotification]) { int LAC,MNc; if (cellInfo[(NSString*)kCTRegistrationGsmLac]) { LAC = [cellInfo[(NSString*)kCTRegistrationGsmLac] intValue]; } else if (data[(NSString*)kCTRegistrationLac]) { LAC = [cellInfo[(NSString*)kCTRegistrationLac] intValue]; } if (cellInfo[(NSString*)kCTRegistrationGsmCellId]) { CID = [cellInfo[(NSString*)kCTRegistrationGsmCellId] intValue]; } else if (cellInfo[(NSString*)kCTRegistrationCellId]) { CID = [cellInfo[(NSString*)kCTRegistrationCellId] intValue]; } MCC = [[(NSString*)CTSIMSupportCopymobileSubscriberCountryCode(NULL) autorelease] intValue]; MNC = [[(NSString*)CTSIMSupportCopymobileSubscriberNetworkCode(NULL) autorelease] intValue]; } }
3)这返回当前服务的单元塔
struct CTResult { int flag; int a; }; id _CTServerConnectionCreate(CfallocatorRef,int*); #ifdef __LP64__ void _CTServerConnectionGetLOCATIOnAreaCode(id,int*); void _CTServerConnectionGetCellID(id,int*); #else void _CTServerConnectionGetLOCATIOnAreaCode(struct CTResult*,int*); #define _CTServerConnectionGetLOCATIOnAreaCode(connection,LAC) { struct CTResult res; _CTServerConnectionGetLOCATIOnAreaCode(&res,LAC); } void _CTServerConnectionGetCellID(struct CTResult*,int*); #define _CTServerConnectionGetCellID(connection,CID) { struct CTResult res; _CTServerConnectionGetCellID(&res,CID); } #endif
…
int CID,LAC,MNc; id CTConnection = _CTServerConnectionCreate(NULL,null); _CTServerConnectionGetCellID(CTConnection,&CID); _CTServerConnectionGetLOCATIOnAreaCode(CTConnection,&LAC); MCC = [[(NSString*)CTSIMSupportCopymobileSubscriberCountryCode(NULL) autorelease] intValue]; MNC = [[(NSString*)CTSIMSupportCopymobileSubscriberNetworkCode(NULL) autorelease] intValue];
在ARM64(iPhone 5S)上,所有CoreTelephony函数都接受struct CTResult参数的问题.显然,64位版本的CoreTelephony导出这些函数,而没有结构化的CTResult参数.因为如果你像以前一样调用这些函数,那么你将会在ARM64中收到错误 – 参数会出错.我更新了函数声明,使它们可以在32位和64位ARM架构上工作.我测试了它,它适用于iPhone 4S和iPhone 5s.
这仅适用于ARM64.如果您为32位ARM架构构建项目,那么就没有这样的问题.您的应用程序将使用32位版本的CoreTelephony,该版本需要使用struct CTResult参数.
8.3更新
从iOS 8.3起,所有上述解决方案都需要授权才能工作
<key>com.apple.CommCenter.fine-grained</key> <array> <String>spi</String> </array>
不仅单元监视器受到保护,而且似乎所有CoreTelephony通知现在都要求该权限工作.例如,kCTmessageReceivedNotification也受到影响.
以上是大佬教程为你收集整理的在iOS 5.1中获取CellID,MCC,MNC,LAC和网络全部内容,希望文章能够帮你解决在iOS 5.1中获取CellID,MCC,MNC,LAC和网络所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。