【问题标题】:Ios how to identify the type of equipment iphone4s and iphone5 [duplicate]ios如何识别iphone 4s和iphone 5的设备类型[重复]
【发布时间】:2012-12-26 04:35:17
【问题描述】:

可能重复:
Determine device (iPhone, iPod Touch) with iPhone SDK

ios如何判断iphone3gs iphone4 iphone4s和iphone5的设备类型?我知道[[UIScreen mainScreen] scale],但是如何知道设备的类型,比如 iphone4 和 iphone5

【问题讨论】:

标签: iphone ios scale


【解决方案1】:

按照下面的代码,它会满足你的需要。

#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define IS_IPOD   ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] )
#define IS_IPAD   ( [[[UIDevice currentDevice] model] isEqualToString:@"iPad"] )
#define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f


if(IS_IPHONE_5_SCREEN)
{
    if(IS_IPHONE)
        NSLog(@"Hey, this is an iPhone 5 screen!");
    else if(IS_IPOD)
        NSLog(@"Hey, this is an iPod 5 screen!");
    else
        NSLog(@"Hey, this is a simulator screen with iPhone 5 screen height!");
}
else if(IS_IPHONE_4_SCREEN)
{
    if(IS_IPHONE)
        NSLog(@"Hey, this is a lower iPhone screen than 5!");
    else if(IS_IPOD)
        NSLog(@"Hey, this is a lower iPod screen than 5!");
    else
        NSLog(@"Hey, this is a lower simulator screen than 5!");
}
else if(IS_IPAD){
    NSLog(@"Hey, this is an iPad screen!");
}
else{
    NSLog(@"Hey, this is an ipad simulator screen!");
}

享受吧!干杯!

【讨论】:

    猜你喜欢
    • 2012-09-26
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2015-02-11
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多