iphone 如何获取iphone的硬件版本以及系统信息

本文介绍了通过自定义类和sysctl系统调用获取iPhone设备的硬件版本信息的方法,包括如何区分不同型号的iPhone,如从系统名称和版本推测设备为iPhone3GS。

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

获取iphone的系统信息使用[UIDevice currentDevice],信息如下:

[[UIDevice currentDevice] systemName]:系统名称,如iPhone OS

[[UIDevice currentDevice] systemVersion]:系统版本,如4.2.1

[[UIDevice currentDevice] model]:The model of the device,如iPhone或者iPod touch

[[UIDevice currentDevice] uniqueIdentifier]:设备的惟一标识号,deviceID

[[UIDevice currentDevice] name]:设备的名称,如 张三的iPhone

[[UIDevice currentDevice] localizedModel]:The model of the device as a localized string,类似model

详见http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html

但是以上的信息貌似无法得到设备的硬件信息,例如一个iphone3GS,系统升级到了iphone4。此时使用systemVersion得到的应该是4.x.x,那我们如何知道该设备为iphone3GS呢。网上流传一个方法,经测试应该是有用的。

自定义一个类:

#import <Foundation/Foundation.h>

@interface UIDeviceHardware : NSObject {  

}

- (NSString *) platform;

- (NSString *) platformString;

@end

#import "UIDeviceHardware.h"

#include <sys/types.h>

#include <sys/sysctl.h>

@implementation UIDeviceHardware

- (NSString *) platform{

size_t size;

sysctlbyname("hw.machine", NULL, &size, NULL, 0);

char *machine = malloc(size);

sysctlbyname("hw.machine", machine, &size, NULL, 0);

NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];

free(machine);

return platform;

}

- (NSString *) platformString{

NSString *platform = [self platform];

if ([platform isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";

if ([platform isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";

if ([platform isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";

if ([platform isEqualToString:@"iPhone3,1"])    return @"iPhone 4";

if ([platform isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";

if ([platform isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";

if ([platform isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";

if ([platform isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";

if ([platform isEqualToString:@"iPad1,1"])      return @"iPad";

if ([platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"])         return@"iPhone Simulator";

return platform;

}

@end

使用[[[UIDeviceHardware alloc] init] platform]应该就可以得到设备的硬件版本。(源码

转载于:https://www.cnblogs.com/greywolf/archive/2012/12/07/2807573.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值