Ios 通过Objective-C中的CoreTephony.framework私有API获取MCC和MNC

Ios 通过Objective-C中的CoreTephony.framework私有API获取MCC和MNC,ios,objective-c,iphone-privateapi,core-telephony,Ios,Objective C,Iphone Privateapi,Core Telephony,我需要获取当前国家/地区的MCC和MNC代码(不从SIM卡母国的CTCarrier类获得) 我为corethony.framework使用私有API。在我的设备上,一切正常。但是在方法CellMonitorCallback中的其他设备上,我们获得cells=NULL 也许有人能帮我做错事 #导入“amcorephone.h” #进口 #进口 结构计算结果 { int标志; INTA; }; 外部CFStringRef常量kCTCellMonitorCellType; 外部CFStringRef

我需要获取当前国家/地区的
MCC
MNC
代码(不从SIM卡母国的CTCarrier类获得)

我为
corethony.framework
使用私有API。在我的设备上,一切正常。但是在方法
CellMonitorCallback
中的其他设备上,我们获得
cells=NULL

也许有人能帮我做错事


#导入“amcorephone.h”
#进口
#进口
结构计算结果
{
int标志;
INTA;
};
外部CFStringRef常量kCTCellMonitorCellType;
外部CFStringRef常量kCTCellMonitorCellTypeServing;
外部CFStringRef常量kCTCellMonitorCellTypeNeighbor;
外部CFStringRef常量kCTCellMonitorCellId;
外部CFStringRef常量kCTCellMonitorLAC;
外部CFStringRef常量kCTCellMonitorMCC;
外部CFStringRef常量kCTCellMonitorMNC;
外部CFStringRef常量kCTCellMonitorUpdateNotification;
idctserverconnectioncreate(CFAllocatorRef,void*,int*);
void CTServerConnectionAddToRunLoop(id,CFRunLoopRef,CFStringRef);
mach_port_t_CTServerConnectionGetPort(id);
#ifdef_uulp64__
void CTServerConnectionRegisterCallService(id);
void ctserverconnectionnRegisterCallService(id,int*);
void CTServerConnectionRegisterForNotification(id,CFStringRef);
void CTServerConnectionCellMonitorStart(id);
void CTServerConnectionCellMonitorStop(id);
void CTServerConnectionCellMonitorCopyCellInfo(id,void*,CFArrayRef*);
void ctserverconnectionsinhomescountry(id,void*,int*);
void ctserverconnectioncopyconcountrycode(id,void*,CFStringRef);
#否则
void CTServerConnectionRegisterCallService(struct-CTResult*,id);
#定义CTServerConnectionRegisterCallService(连接){struct-CTResult-res;CTServerConnectionRegisterCallService(&res,connection);}
void CTServerConnectionRegisterForNotification(struct-CTResult*,id,CFStringRef);
#定义CTServerConnectionRegisterForNotification(连接,通知){struct CTResult res;CTServerConnectionRegisterForNotification(&res,连接,通知);}
void CTServerConnectionCellMonitorStart(struct-CTResult*,id);
#定义{CTServerConnectionCellMonitorStart(连接){struct CTResult res;{CTServerConnectionCellMonitorStart(&res,连接);}
void CTServerConnectionCellMonitorStop(struct-CTResult*,id);
#定义CTServerConnectionCellMonitorStop(连接){struct CTResult res;CTServerConnectionCellMonitorStop(&res,connection);}
void CTServerConnectionCellMonitorCopyCellInfo(struct-CTResult*,id,void*,CFArrayRef*);
#定义CTServerConnectionCellMonitorCopyCellInfo(连接,tmp,单元格){struct CTResult res;CTServerConnectionCellMonitorCopyCellInfo(&res,连接,tmp,单元格);}
void ctserverconnectionsinhomescountry(struct-CTResult*,id,int*);
#定义CTServerConnectionsinHomeCountry(connection,isHomeCountry){struct CTResult res;_CTServerConnectionsinHomeCountry(&res,connection,&isHomeCountry);}
#恩迪夫
@无线电话的实现
{
CTCarrier*\u carrier;
CTID连接;
马赫端口;
}
+(instancetype)sharedInstance
{
静态AMCORE电话*实例;
静态调度一次;
一次发送(一次发送)^{
实例=[[AMCORETERONE alloc]init_true];
});
返回实例;
}
-(instancetype)init_true
{
if(self=[super init]){
_carrier=[[CTTelephonyNetworkInfo新]subscriberCellularProvider];
}
回归自我;
}
-(无效)启动监控{
#if TARGET_IPHONE_模拟器
返回;
#否则
CTConnection=\u CTServerConnectionCreate(kCFAllocatorDefault,CellMonitorCallback,NULL);
_CTServerConnectionRegisterForNotification(CTConnection、kCTCellMonitorUpdateNotification);
端口=CTServerConnectionGetPort(CTConnection);
CFMachPortRef=CFMachPortCreateWithPort(kCFAllocatorDefault,port,NULL,NULL);
CFRunLoopSourceRef rlref=CFMachPortCreateRunLoopSource(kcfolocatordefault,ref,0);
CFRunLoopRef currentloop=CFRunLoopGetCurrent();
CFRunLoopAddSource(currentRunLoop、rlref、kCFRunLoopCommonModes);
_CTServerConnectionCellMonitorStart(CTConnection);
#恩迪夫
}
-(d)停止监测{
_CTServerConnectionCellMonitorStop(CTConnection);
}
int CellMonitorCallback(id连接、CFStringRef字符串、CFDictionaryRef字典、void*数据)
{
int-tmp=0;
CFArrayRef单元格=NULL;
_CTServerConnectionCellMonitorCopyCellInfo(连接,(void*)和tmp,&cells);
如果(单元格==NULL)
{
返回0;
}
用于(u桥NSArray*)单元中的(NSDictionary*单元)
{
国际拉丁美洲和加勒比海、西德、中冶、跨国公司;
如果([cell[(\uu bridge NSString*)kCTCellMonitorCellType]是相等字符串:(\uu bridge NSString*)kCTCellMonitorCellType服务])
{
LAC=[cell[(_桥NSString*)kCTCellMonitorLAC]intValue];
CID=[cell[(uu桥NSString*)kCTCellMonitorCellId]intValue];
MCC=[cell[(uuu桥NSString*)kCTCellMonitorMCC]intValue];
MNC=[cell[(uu桥NSString*)kCTCellMonitorMNC]intValue];
}
如果([cell[(\uu bridge NSString*)kCTCellMonitorCellType]为相等字符串:(\uu bridge NSString*)kCTCellMonitorCellTypeNeighbor])
{
}
}
CFD释放(细胞);
返回0;
}
@结束

我认为问题在于使用私有api,所以你不能在非越狱手机上运行你的应用程序。“我和你一样在研究这件事,但有点晚了:)我发现它可以在iOS 8.3上运行,”它说


从iOS 8.3开始,上述所有解决方案都需要工作权利

<key>com.apple.CommCenter.fine-grained</key>
<array>
    <string>spi</string>
</array>
com.apple.CommCenter.fine-grained
这是我能找到的唯一示例代码


我想您已经知道答案了,但这可能会帮助其他人,因为很难找到:)

从iOS 8.3开始,以上所有解决方案都需要授权才能工作

<key>com.apple.CommCenter.fine-grained</key>
<array>
    <string>spi</string>
</array>
com.apple.CommCenter.fine-grained
spi
确实如此
<key>com.apple.CommCenter.fine-grained</key>
<array>
    <string>spi</string>
</array>