如何擷取iphone的硬體版本以及系統資訊

來源:互聯網
上載者:User

 

reference:

http://blog.csdn.net/xiaoguan2008/article/details/6582699

 

 

擷取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]應該就可以得到裝置的硬體版本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.