iPhone/iPad/iPod touch编程时版本区分
2012-12-10 17:47
459 查看
写程序时,可能需要对应各种不同的iPhone iOS的不同,型号的不同,区分代码如下:
可以从 UIDevice 的属性 model 得到在现在执行的环境。例子如下:
NSString *modelname = [[UIDevice currentDevice]model];
if ([modelname isEqualToString:@"iPhone"]) {
// iPhone
}
if ([modelname isEqualToString:@"IPod Touch"]) {
// iPod touch
}
if ([modelname isEqualToString:@"iPhone Simulator"]) {
// iPhone Simulator
}
也可以通过宏定义区分
#if TARGET_OS_IPHONE
// iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
// iPhone Simulator
#endif
#if !TARGET_IPHONE_SIMULATOR
// iPhone Device
#endif
ios设备版本的区分-iphone3gs,iphone4....
ios提供了几种c函数来获得相应信息如下
struct utsname u;
uname(&u); ///-----get device struct info
NSString *machine = [NSString stringWithCString:u.machine];
if ([machine isEqualToString:@"iPhone1,1"]) {
// iPhone 1G
}
if ([machine isEqualToString:@"iPhone1,2"]) {
// iPhone 3G
}
if ([machine isEqualToString:@"iPhone2,1"]) {
// iPhone 3GS
}
if ([machine isEqualToString:@"iPod1,1"]) {
// iPod touch 1G
}
if ([machine isEqualToString:@"iPod2,1"]) {
// iPod touch 2G
}
if ([machine isEqualToString:@"iPod3,1"]) {
// iPod touch Late2009
}
或者
- (NSString *) platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);///-----get device struct info
/*
Possible values:
"iPhone1,1" = iPhone 1G
"iPhone1,2" = iPhone 3G
"iPhone2,1" = iPhone 3GS
"iPod1,1" = iPod touch 1G
"iPod2,1" = iPod touch 2G
*/
NSString *platform = [NSString stringWithCString:machine];
free(machine);
return platform;
}
可以从 UIDevice 的属性 model 得到在现在执行的环境。例子如下:
NSString *modelname = [[UIDevice currentDevice]model];
if ([modelname isEqualToString:@"iPhone"]) {
// iPhone
}
if ([modelname isEqualToString:@"IPod Touch"]) {
// iPod touch
}
if ([modelname isEqualToString:@"iPhone Simulator"]) {
// iPhone Simulator
}
也可以通过宏定义区分
#if TARGET_OS_IPHONE
// iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
// iPhone Simulator
#endif
#if !TARGET_IPHONE_SIMULATOR
// iPhone Device
#endif
ios设备版本的区分-iphone3gs,iphone4....
ios提供了几种c函数来获得相应信息如下
struct utsname u;
uname(&u); ///-----get device struct info
NSString *machine = [NSString stringWithCString:u.machine];
if ([machine isEqualToString:@"iPhone1,1"]) {
// iPhone 1G
}
if ([machine isEqualToString:@"iPhone1,2"]) {
// iPhone 3G
}
if ([machine isEqualToString:@"iPhone2,1"]) {
// iPhone 3GS
}
if ([machine isEqualToString:@"iPod1,1"]) {
// iPod touch 1G
}
if ([machine isEqualToString:@"iPod2,1"]) {
// iPod touch 2G
}
if ([machine isEqualToString:@"iPod3,1"]) {
// iPod touch Late2009
}
或者
- (NSString *) platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);///-----get device struct info
/*
Possible values:
"iPhone1,1" = iPhone 1G
"iPhone1,2" = iPhone 3G
"iPhone2,1" = iPhone 3GS
"iPod1,1" = iPod touch 1G
"iPod2,1" = iPod touch 2G
*/
NSString *platform = [NSString stringWithCString:machine];
free(machine);
return platform;
}
相关文章推荐
- mmsplayer for ios 支持iphone ,ipad,ipod touch 版本已经完成。
- mmsplayer for ios 版本已经完成。支持iphone,ipod touch,ipad
- mmsplayer for ios 版本已经完成。支持iphone,ipod touch,ipad
- mmsplayer for ios 版本已经完成。支持iphone,ipod touch,ipad
- mmsplayer for ios 版本已经完成。支持iphone,ipod touch,ipad
- 在iPhone/iPad/iPod touch中使用ARM处理器的NEON技术
- iphone、ipod Touch、ipad触屏时的js事件
- 每日分享 - 检测iPhone/iPod Touch/iPad设备类型
- Apple发布适用于iPhone,iPad和iPod Touch的iOS 12 Beta 10和Public Beta 8
- いつでもどこでも本格的に麻雀&チュートリアルが充実!iPhone/iPod touch/iPad向け「雀龍門Mobile」をiPadで遊んでみました
- iPhone/iPad/iPod Touch各设备参数对比
- [手机取证] iOS 4 (iPhone/iPad/iPod Touch) 密码破解
- 如何清理ipod touch iPhone ipad的“其他”文件
- iphone、ipod Touch、ipad触屏时的js事件
- 检测iPhone/iPod Touch/iPad设备类型 .
- 检测iPhone/iPod Touch/iPad设备类型
- 如何在程序中判断硬件的机型(是ipad还是iphone/ipod touch)
- How to find crash logs for iPhone, iPod Touch or iPad applications
- italki Messenger for iPhone 3GS, iPhone 4, iPhone 4S, iPhone 5, iPod touch (3rd generation), iPod touch (4th generation), iPod touch (5th generation) and iPad on the iTunes App Store