Code used to detect iPhone/iPod Touch/iPad devices

Source: Internet
Author: User
This Section detects iPhone/iPod Touch/iPad device types Code Share by cocoachina member qqn_pipi, post address http://www.cocoachina.com/bbs/read.php? Tid-20994.html # import Foundation/Foundation. h # import sys/utsname. h Enum {model_iphone_simulator this Section detects the iPhone/iPod Touch/iPad device type code by cocoachina member "qqn_pipi" to share, post address http://www.cocoachina.com/bbs/read.php? Tid-20994.html
# 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 {
// Cocould be an iPhone V1 or iPhone 3G (Model shocould be "iPhone ")
Struct utsname U;

// U. Machine cocould 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.