一些有用的device信息,可能有些是私有API

原文地址:http://hi.baidu.com/marktian/item/e0f555ee0e08b2225a2d64e0

1. 手机号码:
这个也是undocument api

NSString* phoneNumber = CTSettingCopyMyPhoneNumber();


2. 总磁盘大小:

NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
[fattributes objectForKey:NSFileSystemSize];

剩余空间:

[fattributes objectForKey:NSFileSystemFreeSize];


3. 内存大小:


    size_t size = sizeof(int);
    int results;
    int mib[2] = {CTL_HW, HW_PHYSMEM};

    sysctl(mib, 2, &results, &size, NULL, 0);


4. 

        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;
    }
这个可知网络类型。

5. 

cpu和总线频率:
        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);

 

5. 

得到4种内存信息:

        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
//                                                 ];

        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值