搞了一个来月的这个东西了,还是没有完全解决问题,下面方法可以获取简单的Cell信息,
方法一:
//CoreTelephony.h
//主要就这两个结构体,其他需要的话,自己添加
struct CTServerConnection
{
int a;
int b;
CFMachPortRefmyport;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
};
struct CellInfo
{
int servingmnc;
int network;
int location;
int cellid;
int station;
int freq;
int rxlevel;
// int freq;
int c1;
int c2;
};

//.m
#import "GetGsmInfo.h"
#import "CoreTelephony.h"
#include <dlfcn.h>

CFMachPortRef port;
struct CTServerConnection *sc=NULL;
struct CTServerConnection scc;
struct CellInfo cellinfo;
int b;
int t1;

@implementationGetGsmInfo

int callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
printf("Callback called\n");

return0;
}

- (void) getCellInfo
{
int cellcount;

char* sdk_path = "/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony";
int* handle =dlopen(sdk_path, RTLD_LAZY);
void (*CTServerConnectionCellMonitorGetCellInfo)() = dlsym(handle, "_CTServerConnectionCellMonitorGetCellInfo");
int* (*CTServerConnectionCellMonitorGetCellCount)() = dlsym(handle, "_CTServerConnectionCellMonitorGetCellCount");
void (*CTServerConnectionCellMonitorStart)() = dlsym(handle, "_CTServerConnectionCellMonitorStart");
struct CTServerConnection * (*CTServerConnectionCreate)() = dlsym(handle, "_CTServerConnectionCreate");
int (*CTServerConnectionGetPort)() = dlsym(handle, "_CTServerConnectionGetPort");

sc=CTServerConnectionCreate(kCFAllocatorDefault, callback, &t1);

for(b=0;b<cellcount;b++)

NSAutoreleasePool* pool = [[NSAutoreleasePoolalloc] init];

memset(&cellinfo, 0, sizeof(struct CellInfo));
int ts = 0;

/** 这个方法的问题出现在这里,3.0以前的版本是4个参数,运行后会崩溃,这个我花了很长时间发现是5个参数,不过获取的结果不理想,只获取了5个结果,其他4个是错误的,如果有人知道请,跟贴,或告诉我下,谢谢了*/
CTServerConnectionCellMonitorGetCellInfo(&t1, sc, b, &ts, &cellinfo);

printf("Cell Site: %d, MNC: %d, ",b,cellinfo.servingmnc);
printf("LAC: %d, Cell ID: %d, Station: %d, ",cellinfo.location, cellinfo.cellid, cellinfo.station);
printf("Freq: %d, RxLevel: %d, ", cellinfo.freq, cellinfo.rxlevel);
printf("C1: %d, C2: %d\n", cellinfo.c1, cellinfo.c2);

[pool release];
pool = nil;
}

dlclose(handle);
}

把上面的东西直接加,必须在真机上调试(要插上卡哦),才能看到结果哦,其中获取项有MNC,MCC,LAC,CELLID,PXLEVEL,其他四项返回-1,如果有人知道请告诉我下,谢谢了,

方法2:
串口通信,这个方法很实用,可以解决很多问题,这个我也是找网上的资料,只是拿来用罢了,
代码如下:
#include "at.h"

int fd= InitConn(115200);
AT(fd);

char buf[100] = "";

/** 这里是发送的AT命令,如下面的命令,可以获取CELL的一些信息, 还有其他的一些信息,网上找找就有了,不过不是所有的命令都可以用哦,有些iphone没有留接口,有就用到一个命令AT+CCED=0,1,这个可以获取CELL的较详细的信息,但是IPHONE就没有留接口,没法用,悲剧*/
//下面是一些我找到的,可以用的命令
//获取小区信息
//SendStrCmd(fd, "AT+CREG=2;+CREG?\r\n");
//获取当前小区的信号强度
//SendStrCmd(fd, "AT+CSQ\r\n");
//基带信息
//SendStrCmd(fd, "At+xgendata\r\n");
//获得IMSI。这命令用来读取或者识别SIM卡的IMSI(国际移动签署者标识)。在读取IMSI之前应该先输入PIN(如果需要PIN的话)。
//SendStrCmd(fd, "AT+CCID\r\n");
//获得SIM卡的标识。这个命令使模块读取SIM卡上的EF-CCID文件
//SendStrCmd(fd, "AT+CCID\r\n");
//读取信息中心号码
//SendStrCmd(fd, "AT+CSCA?\r\n");
//单元广播信息标识。
//SendStrCmd(fd, "AT+CSCB?\r\n");

SendStrCmd(fd, "AT+XCELLINFO=1\r\n");
while (1) 
{
read(fd, buf, 100);
printf("%s", buf);
memset(buf, 0, 100);
};

使用前,下载我的附件,把它们加入工程,然后用上面的方法就可以获取信息,获取的信息为mcc,mnc,lac,cellid,rssi。还有前后两个整数,应该是标示当前CELL的,

我还想获取更详细的关于CELL的信息,如果有人知道请告诉我下,谢谢,

注意:
在使用上面的方法时,我奉劝使用第二个方法,虽然第一个简单,易操作,但是,有内存问题,程序容易崩溃,现在我也没有解决那个问题,所有用的第二个方法,自己解析AT获取的数据。
还有第二个方法,我是在iphone 3GS上试的,iphone4断口打开了,但是一直获取不到数据,运行不过去,如果有知道原因的,请告诉下,谢谢,

ios获取CELLID,LAC等信息方法的更多相关文章

  1. ios 获取设备相关的信息

    .获取设备的信息 UIDevice *device = [[UIDevice alloc] int]; NSString *name = device.name; //获取设备所有者的名称 NSStr ...

  2. iOS获取通讯录所有联系人信息

    以下是2种方式: 第一种方法: GetAddressBook.h #import <Foundation/Foundation.h> @interface GetAddressBook : ...

  3. IOS 获取更多的设备信息

    ●  如果想获得更多的设备信息,比如 ●  设备型号.CPU情况.内存使用情况.硬盘使用情况 ●  是否越狱.装了哪些传感器.当前运行的进程 ●  ... ... ●  有2种方法获取更多的设备信息 ...

  4. iOS 获取设备的各种信息的方法

    一.目录结构: 获取屏幕宽度与高度 获取设备版本号 获取iPhone名称 获取app版本号 获取电池电量 获取当前系统名称 获取当前系统版本号 获取通用的唯一识别码UUID 获取当前设备IP 获取总内 ...

  5. iOS获取iPhone系统等信息和服务器返回空的异常处理

    前言: 在项目中经常会遇到需要获取系统的信息来处理一些特殊的需求和服务端返回为空的处理,写在这里只是笔记一下. 获取设备的信息 NSLog(@"globallyUniqueString=%@ ...

  6. iOS ---------- 获取设备的各种信息

    一.目录结构: 获取屏幕宽度与高度 获取设备版本号 获取iPhone名称 获取app版本号 获取电池电量 获取当前系统名称 获取当前系统版本号 获取通用的唯一识别码UUID 获取当前设备IP 获取总内 ...

  7. ios 获取手机相关的信息

    获取手机信息      应用程序的名称和版本号等信息都保存在mainBundle的一个字典中,用下面代码可以取出来 //获取版本号 NSDictionary *infoDict = [[NSBundl ...

  8. js获取当前页面的url信息方法

    例如网址:http://localhost:12085/My/OrderM.aspx 设置或获取对象指定的文件名或路径. alert(window.location.pathname) 输出结果:/M ...

  9. js获取当前页面url信息方法(JS获取当前网址信息)

    设置或获取对象指定的文件名或路径. alert(window.location.pathname) 设置或获取整个 URL 为字符串. alert(window.location.href); 设置或 ...

随机推荐

  1. 监控 Linux Unix Solaris AIX, swap page in / swap page out

    vmstat 的 pi/po si/so --监控一天 vmstat 5 17280> vmstat.txt sar -W 1.得到数据 (linux 的 /var/log/sar/saX 自带 ...

  2. .net 连接数据库

    "@"符号是防止将后面字符串中的"\"解析为转义字符. using System.Data; using System.Data.SqlClient; ... ...

  3. zabbix3.0.4 部署之四 (LNAP > PHP安装)

    1.安装依赖 安装epel-release源 安装 libiconv-1.14.tar.gz (这个还有个devl包)  libmcrypt-2.5.8.tar.gz   mhash-0.9.9.9. ...

  4. Hbase WAL线程模型源码分析

    版权声明:本文由熊训德原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/257 来源:腾云阁 https://www.qclo ...

  5. 识别有效的IP地址和掩码并进行分类统

    #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int c ...

  6. centos 安装php5.6

    检查当前安装包 yum list installed | grep php 删除当前安装包 yum remove php.i686 php-bcmath.i686 php-cli.i686 php-c ...

  7. ios 打包

    /usr/bin/xcodebuild -scheme Moon -sdk iphoneos -workspace Moon.xcworkspace -configuration Release cl ...

  8. ASP.NET中的Session怎么正确使用[转]

    Session对象用于存储从一个用户开始访问某个特定的aspx的页面起,到用户离开为止,特定的用户会话所需要的信息.用户在应用程序的页面切换时,Session对象的变量不会被清除. 对于一个Web应用 ...

  9. 【仿真】【modelsim】:verilog功能仿真流程

    一.编写verilog源文件,在diamond中编译.编写testbench文件.在diamond设置中将仿真工具设置为modelsim,运行仿真向导 二.自动进入modelsim, 编译全部 运行仿 ...

  10. 关于PDF文件无法打印的问题的解决办法

    在这里用到一个软件 PDFSpliter可以直接在网上下载.下载安装完之后 1:打开软件 2,点击   PDF合并  按钮 3,找到无法打印的文件 4,单击开始,文件另存为 5,另存为后的文件就可以打 ...