IOS gets the current Apple device model (true machine test is valid, the simulator only outputs display simulator)

Source: Internet
Author: User

IOS get current Apple device model code:


-(nsstring*) Dodeviceplatform
{
size_t size;

int NR = Sysctlbyname ("Hw.machine", NULL, &size, null,0);

Char*machine = (char*) malloc (size);
NR = Sysctlbyname ("Hw.machine", Machine, &size,null, 0);

NSString *platform = [NSString stringwithcstring:machine encoding:nsutf8stringencoding];

Free (machine);


if ([Platform isequaltostring:@ "iphone1,1"]) return @ "IPhone 1G";
if ([Platform isequaltostring:@ "iphone1,2"]) return @ "IPhone 3G";
if ([Platform isequaltostring:@ "iphone2,1"]) return @ "IPhone 3GS";
if ([Platform isequaltostring:@ "iphone3,1"]) return @ "IPhone 4";
if ([Platform isequaltostring:@ "iphone3,3"]) return @ "Verizon IPhone 4";
if ([Platform isequaltostring:@ "iphone4,1"]) return @ "IPhone 4S";
if ([Platform isequaltostring:@ "iphone5,1"]) return @ "IPhone 5 (GSM)";
if ([Platform isequaltostring:@ "iphone5,2"]) return @ "IPhone 5 (GSM+CDMA)";
if ([Platform isequaltostring:@ "iphone5,3"]) return @ "IPhone 5c (GSM)";
if ([Platform isequaltostring:@ "iphone5,4"]) return @ "IPhone 5c (GSM+CDMA)";
if ([Platform isequaltostring:@ "iphone6,1"]) return @ "IPhone 5s (GSM)";
if ([Platform isequaltostring:@ "iphone6,2"]) return @ "IPhone 5s (GSM+CDMA)";
if ([Platform isequaltostring:@ "iphone7,1"]) return @ "IPhone 6 Plus";
if ([Platform isequaltostring:@ "iphone7,2"]) return @ "IPhone 6";
if ([Platform isequaltostring:@ "iphone8,1"]) return @ "IPhone 6s Plus";
if ([Platform isequaltostring:@ "iphone8,2"]) return @ "IPhone 6s";
if ([Platform isequaltostring:@ "ipod1,1"]) return @ "ipod touch 1G";
if ([Platform isequaltostring:@ "ipod2,1"]) return @ "ipod touch 2G";
if ([Platform isequaltostring:@ "ipod3,1"]) return @ "ipod touch 3G";
if ([Platform isequaltostring:@ "ipod4,1"]) return @ "ipod touch 4G";
if ([Platform isequaltostring:@ "ipod5,1"]) return @ "ipod touch 5G";
if ([Platform isequaltostring:@ "ipad1,1"]) return @ "IPad";
if ([Platform isequaltostring:@ "ipad2,1"]) return @ "IPad 2 (WiFi)";
if ([Platform isequaltostring:@ "ipad2,2"]) return @ "IPad 2 (GSM)";
if ([Platform isequaltostring:@ "ipad2,3"]) return @ "IPad 2 (CDMA)";
if ([Platform isequaltostring:@ "ipad2,4"]) return @ "IPad 2 (WiFi)";
if ([Platform isequaltostring:@ "ipad2,5"]) return @ "IPad Mini (WiFi)";
if ([Platform isequaltostring:@ "ipad2,6"]) return @ "IPad Mini (GSM)";
if ([Platform isequaltostring:@ "ipad2,7"]) return @ "IPad Mini (GSM+CDMA)";
if ([Platform isequaltostring:@ "ipad3,1"]) return @ "IPad 3 (WiFi)";
if ([Platform isequaltostring:@ "ipad3,2"]) return @ "IPad 3 (GSM+CDMA)";
if ([Platform isequaltostring:@ "ipad3,3"]) return @ "IPad 3 (GSM)";
if ([Platform isequaltostring:@ "ipad3,4"]) return @ "IPad 4 (WiFi)";
if ([Platform isequaltostring:@ "ipad3,5"]) return @ "IPad 4 (GSM)";
if ([Platform isequaltostring:@ "ipad3,6"]) return @ "IPad 4 (GSM+CDMA)";
if ([Platform isequaltostring:@ "ipad4,1"]) return @ "IPad Air (WiFi)";
if ([Platform isequaltostring:@ "ipad4,2"]) return @ "IPad Air (cellular)";
if ([Platform isequaltostring:@ "ipad4,4"]) return @ "IPad Mini 2G (WiFi)";
if ([Platform isequaltostring:@ "ipad4,5"]) return @ "IPad Mini 2G (cellular)";
if ([Platform isequaltostring:@ "ipad5,1"]) return @ "IPad Mini 4 (WiFi)";
if ([Platform isequaltostring:@ "ipad5,2"]) return @ "IPad Mini 4 (cellular)";
if ([Platform isequaltostring:@ "ipad6,8"]) return @ "IPad Pro";
if ([Platform isequaltostring:@ "i386"]) return @ "Simulator";
if ([Platform isequaltostring:@ "x86_64"]) return @ "Simulator";



return platform;

}

Related Article

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.