检测iPhone/iPod Touch/iPad设备类型

检测iPhone/iPod Touch/iPad设备类型,第1张

概述检测iPhone/iPod Touch/iPad设备类型   #import <Foundation/Foundation.h> #import <sys/utsname.h> enum {     MODEL_IPHONE_SIMULATOR,     MODEL_IPOD_TOUCH,     MODEL_IPHONE,     MODEL_IPHONE_3G,     MODEL_IPAD 检测iPhone/iPod touch/iPad设备类型   #import <Foundation/Foundation.h> #import <sys/utsname.h> enum {     MODEL_IPHONE_SIMulATOR,    MODEL_IPOD_touch,    MODEL_IPHONE,    MODEL_IPHONE_3G,    MODEL_IPAD }; @interface DeviceDetection : NSObject + (uint) detectDevice; + (Nsstring *) returnDevicename:(BOol)ignoreSimulator; + (BOol) isIPodtouch; @end #import "DeviceDetection.h" @implementation DeviceDetection + (BOol) isIPodtouch {     int model = [DeviceDetection detectDevice];     if (model == MODEL_IPOD_touch || model == MODEL_IPAD){         //|| model == MODEL_IPHONE_SIMulATOR){         return YES;     }         else {         return NO;     } } + (uint) detectDevice {     Nsstring *model= [[UIDevice currentDevice] model];          // Some iPod touch return "iPod touch",others just "iPod"          Nsstring *iPodtouch = @"iPod touch";     Nsstring *iPodtouchLowerCase = @"iPod touch";     Nsstring *iPodtouchShort = @"iPod";     Nsstring *iPad = @"iPad";          Nsstring *iPhonesimulator = @"iPhone Simulator";          uint detected;          if ([model compare:iPhonesimulator] == NSOrderedSame) {         // iPhone simulator         detected = MODEL_IPHONE_SIMulATOR;     }     else if ([model compare:iPad] == NSOrderedSame) {         // iPad         detected = MODEL_IPAD;     } else if ([model compare:iPodtouch] == NSOrderedSame) {         // iPod touch         detected = MODEL_IPOD_touch;     } else if ([model compare:iPodtouchLowerCase] == NSOrderedSame) {         // iPod touch         detected = MODEL_IPOD_touch;     } else if ([model compare:iPodtouchShort] == NSOrderedSame) {         // iPod touch         detected = MODEL_IPOD_touch;     } else {         // Could be an iPhone V1 or iPhone 3G (model should be "iPhone")         struct utsname u;                  // u.machine Could be "i386" for the simulator,"iPod1,1" on iPod touch,"iPhone1,1" on iPhone V1 & "iPhone1,2" on iPhone3G                  uname(&u);                  if (!strcmp(u.machine,1")) {             detected = MODEL_IPHONE;         } else {             detected = MODEL_IPHONE_3G;         }     }     return detected; } + (Nsstring *) returnDevicename:(BOol)ignoreSimulator {     Nsstring *returnValue = @"UnkNown";          switch ([DeviceDetection detectDevice]) {         case MODEL_IPHONE_SIMulATOR:             if (ignoreSimulator) {                 returnValue = @"iPhone 3G";             } else {                 returnValue = @"iPhone Simulator";             }             break;         case MODEL_IPOD_touch:             returnValue = @"iPod touch";             break;         case MODEL_IPHONE:             returnValue = @"iPhone";             break;         case MODEL_IPHONE_3G:             returnValue = @"iPhone 3G";             break;         default:             break;     }          return returnValue; } @end 总结

以上是内存溢出为你收集整理的检测iPhone/iPod Touch/iPad设备类型全部内容,希望文章能够帮你解决检测iPhone/iPod Touch/iPad设备类型所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1089585.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存