4

可能重复:
如何通过代码查找 iPhone/iPod 设备型号(3G、3GS、4、4S)?
检测设备类型

我想以编程方式识别 iphone 的型号(3g、4s、5)。

那么我怎样才能找到它呢?

4

6 回答 6

12

您可以通过以下条件轻松检测 iphone 3gs-4s、iphone5 和 iPad:-

 if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
 {
     if ([[UIScreen mainScreen] bounds].size.height == 568)
     {

          //iphone 5
     }
     else
     {
         //iphone 3.5 inch screen iphone 3g,4s 
     }
 }
 else
 {
        //[ipad]
 }

只需在此检测设备类型上访问我的答案

于 2012-12-26T09:19:10.843 回答
6

请使用以下代码

#import <sys/utsname.h>

NSString* machineName()
{
    struct utsname systemInfo;
    uname(&systemInfo);

    return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}

使用以下代码识别您的设备类型

if([machineName() isEqualToString:@"iPhone1,2"])
{
    deviceType = @"iPhone 3G";
}
else if([machineName() isEqualToString:@"iPhone2,1"])
{
    deviceType = @"iPhone 3GS";
}
else if([machineName() isEqualToString:@"iPhone3,1"] || [machineName() isEqualToString:@"iPhone3,2"] || [machineName() isEqualToString:@"iPhone3,3"])
{
    deviceType = @"iPhone 4";
}
else if([machineName() isEqualToString:@"iPhone4,1"])
{
    deviceType = @"iPhone 4S";
}
else if([machineName() isEqualToString:@"iPhone5,1"])
{
    deviceType = @"iPhone 5";
}
else if([machineName() isEqualToString:@"iPod1,1"])
{
    deviceType = @"iPod Touch 1G";
}
else if([machineName() isEqualToString:@"iPod2,1"] || [machineName() isEqualToString:@"iPod2,2"])
{
    deviceType = @"iPod Touch 2G";
}
else if([machineName() isEqualToString:@"iPod3,1"])
{
    deviceType = @"iPod Touch 3G";
}
else if([machineName() isEqualToString:@"iPod4,1"])
{
    deviceType = @"iPod Touch 4G";
}
else if([machineName() isEqualToString:@"iPod5,1"])
{
    deviceType = @"iPod Touch 5G";
}
于 2012-12-26T09:30:04.553 回答
4

您可以使用Erica Sadun的 UIDevice (Hardware) 类别

它可以用作:

[[UIDevice currentDevice] platformType]   // ex: UIDevice4GiPhone

[[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"
于 2012-12-26T09:16:07.217 回答
2

您可以为此使用以下代码:

NSString *device()
{
    struct utsname devInfo;
    uname(&devInfo);

    return [NSString stringWithCString:devInfo.machine encoding:NSUTF8StringEncoding];
}

确保您导入 #import <sys/utsname.h>

于 2012-12-26T09:24:12.377 回答
1

嗨,请使用下面的代码

[UIDevice currentDevice] platformType]   // returns UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // returns @"iPhone 4G"

或者请检查ratina

+ (BOOL) isRetina
{
    if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
        return [[UIScreen mainScreen] scale] == 2.0 ? YES : NO;

    return NO;
}

或者查看ios版本

   + (BOOL) isIOS5
    {
        NSString *os5 = @"5.0";
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

        //    currSysVer = @"5.0.1";
        if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedAscending) //lower than 4
        {
            return NO;
        }
        else if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedDescending) //5.0.1 and above
        {        
            return YES;
        }
        else // IOS 5
        {
            return YES;
        }

        return NO;
    }
于 2012-12-26T09:21:16.513 回答
0

您可以使用uidevice-extension获得这些 您需要的是以下功能:

- (NSString *) platform;
- (NSString *) hwmodel;
- (NSUInteger) platformType;
- (NSString *) platformString;

来自 UIDevice-Hardware.h

于 2012-12-26T09:19:20.513 回答