显示ios设备信息的程序
以下是运行在本人iphone4上的截图,支持中文简体,中文繁体,英文,支持iphone和ipad,当然由于没有ipad,ipad的测试用的模拟器。
支持iphone4的Retina屏幕。
本来有6个标签,但是iphone的很多信息实在得不到,现在只剩下了4个标签。
这里面的电量精确到0.01,用的undocument api,但是个人感觉总是比右上角系统自己显示的偏低3%以内。
显示当前运行的进程,但是不知道如何得到进程的图标,因此统一用的图标。
一些硬件信息,iphone4的A4 cpu频率实际上得不到,始终显示为0,只好根据手机型号判断,如果是iphone4则显示800Mhz,(据说是1G的cpu降频到800Mhz)。
宣传devdiv的信息。
ipa包如下: FeiPhoneInfo.ipa
图标来源于网络。
每张图中右边的圆圈是ios5的手势触摸的东东。
展开来后是这个样子,可以有效的降低home键的使用。
部分信息是UIDevice里的。
电池信息可以从UIDevice batteryLevel得到,但是只能精确到0.05.
- - (NSDictionary*)batteryLevel
- {
- CFTypeRef blob = IOPSCopyPowerSourcesInfo();
- CFArrayRef sources = IOPSCopyPowerSourcesList(blob);
- CFDictionaryRef pSource = NULL;
- const void *psValue;
- int numOfSources = CFArrayGetCount(sources);
- if (numOfSources == 0)
- {
- CFRelease(blob);
- CFRelease(sources);
- NSLog(@“qhk: Error in CFArrayGetCount”);
- return nil;
- }
- for (int i = 0 ; i < numOfSources ; i++)
- {
- pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i));
- if (!pSource)
- {
- CFRelease(blob);
- CFRelease(sources);
- NSLog(@“qhk: Error in IOPSGetPowerSourceDescription”);
- return nil;
- }
- psValue = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey));
- int curCapacity = 0;
- int maxCapacity = 0;
- // double percent;
- psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSCurrentCapacityKey));
- CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, >curCapacity);
- psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSMaxCapacityKey));
- CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, >maxCapacity);
- // percent = ((double)curCapacity/(double)maxCapacity * 100.0f);
- NSNumber* no1 = [NSNumber numberWithInt:curCapacity];
- NSNumber* no2= [NSNumber numberWithInt:maxCapacity];
- CFRelease(blob);
- CFRelease(sources);
- return [NSDictionary dictionaryWithObjectsAndKeys:no1, @"no1", no2, @"no2", nil];
- // return percent;
- // return (NSInteger)(percent + 0.5f);
- }
- //#endif
- CFRelease(blob);
- CFRelease(sources);
- return nil;
- }
- - (NSString*) doDevicePlatform
- {
- size_t size;
- int nR = sysctlbyname(“hw.machine”, NULL, >size, NULL, 0);
- char *machine = (char *)malloc(size);
- nR = sysctlbyname(“hw.machine”, machine, >size, NULL, 0);
- NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
- free(machine);
- return platform;
- }
比如:
- if ([platform isEqualToString:@"iPhone1,1"])
- {
- return @“iPhone”;
- }
- if ([platform isEqualToString:@"iPhone1,2"])
- {
- return @“iPhone3G”;
- }
- if ([platform isEqualToString:@"iPhone2,1"])
- {
- return @“iPhone3GS”;
- }
- if ([platform isEqualToString:@"iPhone3,1"])
- {
- return @“iPhone4″;
- }
- - (void)printmacinfo
- {
- bool success;
- struct ifaddrs *addrs;
- const struct ifaddrs *cursor;
- const struct sockaddr_dl *dlAddr;
- const uint8_t *base;
- success = getifaddrs(>addrs) == 0;
- if (success)
- {
- cursor = addrs;
- NSInteger idx = 0;
- while (cursor != NULL)
- {
- ++idx;
- NSString* macTitle = nil;
- if ((cursor->ifa_flags > IFF_LOOPBACK) == 0 )
- {
- char* ifaname = (char *)cursor->ifa_name;
- char* addr = inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr);
- printf(“%s ”, ifaname);
- printf(“%s\n”, addr);
- // NSString* tmpstr1 = [NSString stringWithCString:ifaname encoding:NSUTF8StringEncoding];
- // NSString* tmpstr2 = [NSString stringWithCString:addr encoding:NSUTF8StringEncoding];
- // NSString *tmpStr = [NSString stringWithFormat:@"%@ %@", tmpstr1, tmpstr2];
- macTitle = [NSString stringWithFormat:@"%d %s %s", idx, ifaname, addr];
- [_arrKey addObject:macTitle];
- }
- if ( (cursor->ifa_addr->sa_family == AF_LINK)
- >> (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type ==IFT_ETHER)
- )
- {
- dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
- // fprintf(stderr, ” sdl_nlen = %d\n”, dlAddr->sdl_nlen);
- // fprintf(stderr, ” sdl_alen = %d\n”, dlAddr->sdl_alen);
- base = (const uint8_t *) >dlAddr->sdl_data[dlAddr->sdl_nlen];
- printf(“ MAC address ”);
- NSMutableString* tmpString = [[[NSMutableString alloc] initWithString:@“Mac:”] autorelease];
- for (int i = 0; i < dlAddr->sdl_alen; i++)
- {
- if (i != 0)
- {
- printf(“:”);
- [tmpString appendString:@":"];
- }
- printf(“%02x”, base[i]);
- [tmpString appendFormat:@"%02X", base[i]];
- }
- printf(“\n”);
- [_dic setObject:tmpString forKey:macTitle];
- }
- else if (macTitle != nil)
- {
- [_dic setObject:@"" forKey:macTitle];
- }
- cursor = cursor->ifa_next;
- }
- }
- }
- int pageSize = 0;
- size_t length = sizeof(pageSize);
- sysctlbyname(“hw.pagesize”, >pageSize, >length, NULL, 0);
- mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
- vm_statistics_data_t vmstat;
- if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)>vmstat, >count) != KERN_SUCCESS)
- {
- NSLog(@“Failed to get VM statistics.”);
- [_dic setObject:@"Failed to get VM statistics." forKey:KTTMemorySize_Wire];
- }
- else
- {
- float total = vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count;
- float wired = vmstat.wire_count / total * 100;
- float active = vmstat.active_count / total * 100;
- float inactive = vmstat.inactive_count / total * 100;
- float free = vmstat.free_count / total * 100;
- // NSString *str = [NSString stringWithFormat:@"%d %d %d %d %.2f %.2f %.2f %.2f %.0f %.0f"
- // , vmstat.wire_count, vmstat.active_count, vmstat.inactive_count, vmstat.free_count
- // , wired, active, inactive, free
- // , total, total * pageSize
- // ];
- }
- int result;
- mib[0] = CTL_HW;
- mib[1] = HW_CPU_FREQ;
- length = sizeof(result);
- if (sysctl(mib, 2, >result, >length, NULL, 0) < 0)
- {
- perror(“getting cpu frequency”);
- }
- printf(“CPU Frequency = %u hz\n”, result);
- int result2;
- mib[0] = CTL_HW;
- mib[1] = HW_BUS_FREQ;
- length = sizeof(result2);
- if (sysctl(mib, 2, >result2, >length, NULL, 0) < 0)
- {
- perror(“getting bus frequency”);
- }
- printf(“Bus Frequency = %u hz\n”, result);
外部ip访问http://automation.whatismyip.com/n09230945.asp即可知道。
gethostbyname可知内部局域网ip。
- NetworkStatus netstatus = [reachable currentReachabilityStatus];
- switch (netstatus)
- {
- case NotReachable:
- // 没有网络连接
- reachableStatus = NSLocalizedString(@“No Network”, “”);
- break;
- case ReachableViaWWAN:
- // 使用3G网络
- reachableStatus = @“GPRS/3G”;
- break;
- case ReachableViaWiFi:
- // 使用WiFi网络
- reachableStatus = @“WIFI”;
- break;
- }
- size_t size = sizeof(int);
- int results;
- int mib[2] = {CTL_HW, HW_PHYSMEM};
- sysctl(mib, 2, >results, >size, NULL, 0);
- NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
- [fattributes objectForKey:NSFileSystemSize];
- [fattributes objectForKey:NSFileSystemFreeSize];
这个也是undocument api
- NSString* phoneNumber = CTSettingCopyMyPhoneNumber();
- NSArray *getValue(NSString *iosearch)
- {
- mach_port_t masterPort;
- CFTypeID propID = (CFTypeID) NULL;
- unsigned int bufSize;
- kern_return_t kr = IOMasterPort(MACH_PORT_NULL, >masterPort);
- if (kr != noErr) return nil;
- io_registry_entry_t entry = IORegistryGetRootEntry(masterPort);
- if (entry == MACH_PORT_NULL) return nil;
- CFTypeRef prop = IORegistryEntrySearchCFProperty(entry, kIODeviceTreePlane, (CFStringRef) iosearch, nil, kIORegistryIterateRecursively);
- if (!prop) return nil;
- propID = CFGetTypeID(prop);
- if (!(propID == CFDataGetTypeID()))
- {
- mach_port_deallocate(mach_task_self(), masterPort);
- CFRelease(prop);
- return nil;
- }
- CFDataRef propData = (CFDataRef) prop;
- if (!propData)
- {
- CFRelease(prop);
- return nil;
- }
- bufSize = CFDataGetLength(propData);
- if (!bufSize)
- {
- CFRelease(prop);
- return nil;
- }
- NSString *p1 = [[[NSString alloc] initWithBytes:CFDataGetBytePtr(propData) length:bufSize encoding:1] autorelease];
- mach_port_deallocate(mach_task_self(), masterPort);
- CFRelease(prop);
- return [p1 componentsSeparatedByString:@"\0"];
- }
- - (NSString *) imei
- {
- NSArray *results = getValue(@“device-imei”);
- if (results) return [results objectAtIndex:0];
- return nil;
- }
- - (NSString *) serialnumber
- {
- NSArray *results = getValue(@“serial-number”);
- if (results) return [results objectAtIndex:0];
- return nil;
- }
- - (NSString *) backlightlevel
- {
- NSArray *results = getValue(@“backlight-level”);
- if (results) return [results objectAtIndex:0];
- return nil;
- }
显示ios设备信息的程序的更多相关文章
- iOS开发的另类神器:libimobiledevice开源包【类似android adb 方便获取iOS设备信息】
简介 libimobiledevice又称libiphone,是一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备.由于苹果官方并不支持Linux系统,但是Linux上 ...
- 获取iOS设备信息的编程接口
参考资料: [1] 博客园,iOS屏幕尺寸和分辨率了解 [2] 张兴业,获取手机信息(UIDevice.NSBundle.NSLocale), CSDN
- 获取iOS设备信息(内存/电量/容量/型号/IP地址/当前WIFI名称)
1.获取电池电量(一般用百分数表示,大家自行处理就好) 1 2 3 4 -(CGFloat)getBatteryQuantity { return [[UIDevice current ...
- IOS 设备信息读取
let infoDictionary = NSBundle.mainBundle().infoDictionary let appDisplayName: AnyObject? = infoDicti ...
- iOS 设备信息获取
參考:http://blog.csdn.net/decajes/article/details/41807977參考:http://zengrong.net/post/2152.htm1. 获取设备的 ...
- [转]从命令行往 iOS 设备上安装程序
link:http://www.stewgleadow.com/blog/2011/11/05/installing-ios-apps-on-the-device-from-the-command-l ...
- IOS设备信息与机型对照表
http://blog.csdn.net/olsQ93038o99S/article/details/78374343 参考别人的文章吧....
- 转:向IOS设备发送推送通知
背景 SMS 和 MMS 消息是由无线运营商通过设备的电话号码向特定设备提供的.实现 SMS/MMS 的服务器端应用程序的开发人员必须费大量精力才能与现有的封闭电信基础架构进行交互(其中包括获取电话号 ...
- Android开发之Ubuntu上Eclipse不显示手机设备
一.准备工作 A.开启Android设备,用USB数据线连接到Ubuntu系统. B.启用设备的USB调试模试 C.启动Eclipse,在Devices栏会现一个有很多???号的不明设备 ...
随机推荐
- 2016年31款轻量高效的开源JavaScript插件和库
目前有很多网站设计师和开发者喜欢使用由JavaScript开发的插件和库,但同时面临一个苦恼的问题:它们中的大多数实在是太累赘而且常常降低网站的性能.其实,其中也有不少轻量级的插件和库,它们不仅轻巧有 ...
- XPath 语法示例
参考:http://www.w3school.com.cn/xpath/xpath_syntax.asp XPath 使用路径表达式来选取 XML 文档中的节点或节点集.节点是通过沿着路径 (path ...
- Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- hdu5884 Sort(二分+k叉哈夫曼树)
题目链接:hdu5884 Sort 题意:n个有序序列的归并排序.每次可以选择不超过k个序列进行合并,合并代价为这些序列的长度和.总的合并代价不能超过T, 问k最小是多少. 题解:先二分k,然后在k给 ...
- 六个前端开发工程师必备的Web设计模式/模块资源(转)
[导读] Yahoo的设计模式库Yahoo的设计模式库包含了很多可以帮助开发设计人员解决遇到的问题的资源,包括开发中常常需要处理的导航,互动效果及其布局网格等大家常用的组件和模块响应式设计模式库这个响 ...
- CentOS查看软件源提供的软件版本命令
yum list available第二列包更详细的说明:yum info packagename
- mybatis使用
mybatis网站:http://mybatis.github.io/spring/zh/ mybatis spring下载网址:https://github.com/mybatis/spring/r ...
- Htmlhelper—CheckBox自动生成两个input
前言 在之前的一篇文章中小猪分享了Htmlhelper的用法.其中有意思的一个就是Checkbox,有必要单独拿出来讲一讲. Htmlhelper—CheckBox 细心的读者一定发现了当使用类似语法 ...
- 项目构建工具Gradle的使用入门(参考,只表明地址)
Gradle入门介绍:简介 http://blog.jobbole.com/71999/ Gradle入门介绍:第一个Java项目 http://blog.jobbole.com/72558/ Gra ...
- FloatingActionButton增强版,一个按钮跳出多个按钮--第三方开源--FloatingActionButton
FloatingActionButton项目在github上的主页:https://github.com/futuresimple/android-floating-action-button F ...