How to differentiate between iphone4 and iphone 3

前端 未结 9 1389
情歌与酒
情歌与酒 2020-11-28 20:28

I am trying to build a game for the iphone using cocos2d engine. I wanted to know how can I tell a difference whether the user is using iphone 4 or iphone 3 as I wanted to l

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 20:59

    - (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];  
        free(machine);  
        return platform;  
    }  
    
    - (NSString *) platformString  
    {  
        NSString *platform = [self platform];  
        if ([platform isEqualToString:@"iPhone1,1"]) return @"Original iPhone";  
        if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";  
        if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3G[S]"; 
        if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";   
        return @"Unknown";  
    }  
    

提交回复
热议问题