`

检测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, "iPhone1,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文件传输工具 ifunBox_sc中文版(数据线版)支持

    iPhone/ipod touch/ipad文件传输工具 ifunBox_sc中文版(数据线版)支持 iFunBox:PC 端程序,简单、高效,只需要 iTunes 环境支持,数据线传输,速度一般 10MB/S i-FunBox v0.99版本, 更新信息: 1. 传输文件到...

    treemapkit, Cocoa Touch for ( iphone/ipod touch/ipad ).zip

    treemapkit, Cocoa Touch for ( iphone/ipod touch/ipad ) TreemapKitTreemapKit是 Cocoa Touch的treemap实现。 你可以在 iPhone,iPod touch和iPad中显示 TreeMaps 。点击这里看一下简单的演示软件。 许可证...

    iPhone/iPad 绘图应用 Brushes.zip

    iPhone/iPad 绘图应用 Brushes ,Brushes 是一个绘图应用,支持 iPhone, iPod touch 和 iPad。

    iPhone/iPad Keynote

    完全针对 iPad、iPhone 和 iPod touch 构建,使创建包含动画图表和过渡效果的世界一流水平演示文稿变得如此简单,只需触摸和轻按即可。使用全屏幕视图在 iPad、iPhone 或 iPod touch 上演示。或者使用视频镜像在 HDTV ...

    IOS游戏开发:基于IPAD,IPHONE和IPOD TOUCH_超高清pdf

    【内容提要】本书深入探讨了基于iOS的游戏设计、游戏开发根据相关的各类处理方案,并对颇具技巧的难点内容进行深入讨论。... iOS游戏开发 基于iPad,iPhone和iPod Touch. 北京:清华大学出版社, 2015.05.

    iphone ipod touch4 ipad2 连接管理器

    可以使苹果的iphone ipod touch4 ipad2 像电脑的资源管理器一样管理iphone ipod touch4 ipad2 里面的资料文件

    iPhone/iPad Keynote 分卷3

    完全针对 iPad、iPhone 和 iPod touch 构建,使创建包含动画图表和过渡效果的世界一流水平演示文稿变得如此简单,只需触摸和轻按即可。使用全屏幕视图在 iPad、iPhone 或 iPod touch 上演示。或者使用视频镜像在 HDTV ...

    iPhone/iPad Keynote 分卷2

    完全针对 iPad、iPhone 和 iPod touch 构建,使创建包含动画图表和过渡效果的世界一流水平演示文稿变得如此简单,只需触摸和轻按即可。使用全屏幕视图在 iPad、iPhone 或 iPod touch 上演示。或者使用视频镜像在 HDTV ...

    iPhone/iPad Numbers

    完全针对 iPad、iPhone 和 iPod touch 构建,它可让您仅用手指就可以在几分钟内制作出带有表格、图表、照片和图形的吸引人的电子表格。有超过 250 种易于使用的函数可供选择。使用滑块、步进器、弹出式菜单和智能键盘...

    iPhone/iPad Numbers 分卷2

    完全针对 iPad、iPhone 和 iPod touch 构建,它可让您仅用手指就可以在几分钟内制作出带有表格、图表、照片和图形的吸引人的电子表格。有超过 250 种易于使用的函数可供选择。使用滑块、步进器、弹出式菜单和智能键盘...

    ios8 Axure组件库

    本套部件库包含最新的 iOS8 iPhone6 UI Kit ,机身部件库几乎囊括了目前主流的苹果手机和平板电脑产品:iPhone 4S/iPhone 5C/iPhon 5S/iPod Touch/iPhone 6/iPhone 6+/iPad Mini/iPad Mini3/iPad Air/iPad Air2/iPad...

    apple iphone ipod touch ipad WifiTrak 2.6.ipa

    apple设备发现无线接入点,包括隐藏的没有广播的接入点。快来试试吧。

    iPhone/iPad Pages

    这是个免费的iPhone/iPad的Pages...该功能强大的应用程序是专门为 iPad、iPhone 和 iPod touch 设计的。随时随地创建、编辑和查看文稿。Pages 会配合 iCloud 使用,因此您的文稿将在您的所有 iOS 设备上自动地保持最新。

    ios各设备参数比较

    iPhone/iPad/iPod touch各设备参数比较

    同步助手 for windows 最安全的iphone同步工具

    号称史上最安全最易用的iphone/ipod touch/ipad同步工具

    iphone ipad iOS 6.1越狱教程

    该工具支持iPhone3GS/4/4S/5、iPad2/3/4、iPad mini、iTouch5等22款设备的完美越狱。不支持iPhone2G、iPhone3G、iPod Touch1G、iPod touch2G、iPod touch3G、iPad1

    iPhone/iPad Pages 分卷2

    这是个免费的iPhone/iPad的Pages...该功能强大的应用程序是专门为 iPad、iPhone 和 iPod touch 设计的。随时随地创建、编辑和查看文稿。Pages 会配合 iCloud 使用,因此您的文稿将在您的所有 iOS 设备上自动地保持最新。

    iOSDesignStencils, 适用于 iPhone,iPad和 iPod touch设备的iOS应用程序设计模板.zip

    iOSDesignStencils, 适用于 iPhone,iPad和 iPod touch设备的iOS应用程序设计模板 iOS设计模板用于为 iPhone,iPad和 iPod touch设备设计iOS应用程序的模具。 模具为开发者创造了开发者,并提供了UIKit的视图。控制...

    adventure maker PSP,iPhone和iPod Touch游戏制作软件

    它运行于Windows,它允许创建Windows中,PSP,iPhone手机和iPod touch软件。 . 冒险Maker是非常容易使用 。 所有你所要做的的就是导入您的图片,添加一些热点的图片链接到另一个,和你做 ! 冒险Maker是特别...

Global site tag (gtag.js) - Google Analytics