IOS硬件信息采集汇总

这篇博客主要介绍了在iOS平台上进行前端数据采集的工作,包括如何获取CPU类型、设备总内存、应用占用内存以及如何获取MMC和MNC信息,内容涵盖必要的头文件引入和框架需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

年前,一直在做IOS前端数据采集这一块。。所以就整理了下,这些用到的东西...后继有可能还有补充

1.CPU类型获取

需要引入以下头文件,CPU类型放在 mach/machine.h中

#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/machine.h>

+(NSString*)getCPUType
{
    NSMutableString *cpu = [[NSMutableString alloc] init];
    size_t size;
    cpu_type_t type;
    cpu_subtype_t subtype;
    size = sizeof(type);
    sysctlbyname("hw.cputype", &type, &size, NULL, 0);
    
    size = sizeof(subtype);
    sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0);
    
    // values for cputype and cpusubtype defined in mach/machine.h
    if (type == CPU_TYPE_X86)
    {
        [cpu appendString:@"x86 "];
        // check for subtype ...
        
    } else if (type == CPU_TYPE_ARM)
    {
        [cpu appendString:@"ARM"];
        [cpu appendFormat:@",Type:%d",subtype];
    }
    return [cpu autorelease];

}


2.获取设备总内存

+ (NSUInteger)getTotalMemoryBytes
{
    size_t size = sizeof(int);
    int results;
    int mib[2] = {CTL_HW, HW_PHYSMEM};
    sysctl(mib, 2, &results, &size, NULL, 0);
    return (NSUInteger) results/1024/1024;
}


3.获取当前应用所占得内存

+(double)getCurrentApplicationUseMemory
{
    task_basic_info
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值