IOS get current device model information (full) including IPhone7 and Iphone7p_ios

Source: Internet
Author: User
Tags file info one more line uuid

#include <sys/types.h> #include <sys/sysctl.h>//Get Equipment Model + (NSString *) getcurrentdevicemodel {int mib[2]; 
size_t Len; 
Charchar *machine; 
Mib[0] = CTL_HW; 
MIB[1] = Hw_machine; 
Sysctl (MIB, 2, NULL, &len, NULL, 0); 
Machine = malloc (len); 
Sysctl (MIB, 2, machine, &len, NULL, 0); 
NSString *platform = [NSString stringwithcstring:machine encoding:nsasciistringencoding]; 
Free (machine); 
IPhone if ([Platform isequaltostring:@ "iphone1,1"]) return @ "iphone2g"; 
if ([Platform isequaltostring:@ "iphone1,2"]) return @ "IPHONE3G"; 
if ([Platform isequaltostring:@ "iphone2,1"]) return @ "IPHONE3GS"; 
if ([Platform isequaltostring:@ "iphone3,1"]) return @ "IPhone4"; 
if ([Platform isequaltostring:@ "iphone3,2"]) return @ "IPhone4"; 
if ([Platform isequaltostring:@ "iphone3,3"]) return @ "IPhone4"; 
if ([Platform isequaltostring:@ "iphone4,1"]) return @ "iphone4s"; 
if ([Platform isequaltostring:@ "iphone5,1"]) return @ "IPhone5"; if ([Platform isequaltostring:@ "iphone5,2"]) RetuRN @ "IPhone5"; 
if ([Platform isequaltostring:@ "iphone5,3"]) return @ "IPHONE5C"; 
if ([Platform isequaltostring:@ "iphone5,4"]) return @ "IPHONE5C"; 
if ([Platform isequaltostring:@ "iphone6,1"]) return @ "IPhone5S"; 
if ([Platform isequaltostring:@ "iphone6,2"]) return @ "IPhone5S"; 
if ([Platform isequaltostring:@ "iphone7,2"]) return @ "IPhone6"; 
if ([Platform isequaltostring:@ "iphone7,1"]) return @ "Iphone6plus"; 
if ([Platform isequaltostring:@ "iphone8,1"]) return @ "iphone6s"; 
if ([Platform isequaltostring:@ "iphone8,2"]) return @ "Iphone6splus"; 
if ([Platform isequaltostring:@ "iphone8,3"]) return @ "Iphonese"; 
if ([Platform isequaltostring:@ "iphone8,4"]) return @ "Iphonese"; 
if ([Platform isequaltostring:@ "iphone9,1"]) return @ "IPhone7"; 
if ([Platform isequaltostring:@ "iphone9,2"]) return @ "Iphone7plus"; 
ipod touch if ([Platform isequaltostring:@ "ipod1,1"]) return @ "Ipodtouch"; 
if ([Platform isequaltostring:@ "ipod2,1"]) return @ "ipodtouch2g"; if ([Platform isequaltostring:@ "iPod3,1 "]) return @" ipodtouch3g "; 
if ([Platform isequaltostring:@ "ipod4,1"]) return @ "ipodtouch4g"; 
if ([Platform isequaltostring:@ "ipod5,1"]) return @ "ipodtouch5g"; 
if ([Platform isequaltostring:@ "ipod7,1"]) return @ "ipodtouch6g"; 
ipad if ([Platform isequaltostring:@ "ipad1,1"]) return @ "ipad"; 
if ([Platform isequaltostring:@ "ipad2,1"]) return @ "IPad2"; 
if ([Platform isequaltostring:@ "ipad2,2"]) return @ "IPad2"; 
if ([Platform isequaltostring:@ "ipad2,3"]) return @ "IPad2"; 
if ([Platform isequaltostring:@ "ipad2,4"]) return @ "IPad2"; 
if ([Platform isequaltostring:@ "ipad3,1"]) return @ "IPad3"; 
if ([Platform isequaltostring:@ "ipad3,2"]) return @ "IPad3"; 
if ([Platform isequaltostring:@ "ipad3,3"]) return @ "IPad3"; 
if ([Platform isequaltostring:@ "ipad3,4"]) return @ "IPAD4"; 
if ([Platform isequaltostring:@ "ipad3,5"]) return @ "IPAD4"; 
if ([Platform isequaltostring:@ "ipad3,6"]) return @ "IPAD4"; 
The IPad Air if ([Platform isequaltostring:@ "ipad4,1"]) return @ "Ipadair"; if ([Platform IsEqualtostring:@ "ipad4,2"]) return @ "Ipadair"; 
if ([Platform isequaltostring:@ "ipad4,3"]) return @ "Ipadair"; 
if ([Platform isequaltostring:@ "ipad5,3"]) return @ "IPadAir2"; 
if ([Platform isequaltostring:@ "ipad5,4"]) return @ "IPadAir2"; 
IPad Mini if ([Platform isequaltostring:@ "ipad2,5"]) return @ "ipadmini1g"; 
if ([Platform isequaltostring:@ "ipad2,6"]) return @ "ipadmini1g"; 
if ([Platform isequaltostring:@ "ipad2,7"]) return @ "ipadmini1g"; 
if ([Platform isequaltostring:@ "ipad4,4"]) return @ "IPadmini2"; 
if ([Platform isequaltostring:@ "ipad4,5"]) return @ "IPadmini2"; 
if ([Platform isequaltostring:@ "ipad4,6"]) return @ "IPadmini2"; 
if ([Platform isequaltostring:@ "ipad4,7"]) return @ "IPadmini3"; 
if ([Platform isequaltostring:@ "ipad4,8"]) return @ "IPadmini3"; 
if ([Platform isequaltostring:@ "ipad4,9"]) return @ "IPadmini3"; 
if ([Platform isequaltostring:@ "ipad5,1"]) return @ "IPadmini4"; 
if ([Platform isequaltostring:@ "ipad5,2"]) return @ "IPadmini4"; if ([Platform isequaltostring:@)I386 "]) return @" Iphonesimulator "; 
if ([Platform isequaltostring:@ "x86_64"]) return @ "Iphonesimulator"; 
return platform; }

Get Device Information Summary

1, get the information of the equipment

Uidevice *device = [[Uidevice alloc] int]; 
NSString *name = device.name; Gets the name of the device owner 
nsstring *model = device.name;//Get device category 
nsstring *type = Device.localizedmodel;//Get Localized version 
NSString *systemname = device.systemname; Gets the currently running system 
nsstring *systemversion = device.systemversion;//Gets the version of the current system

2, get the device's unique identifier

NSString *identifier = [[[Uidevice Currentdevice] Identifierforvendor] uuidstring];

3. Create a random designator for the system

 (nsstring*) Createuuid {nsstring *id = [[Nsuserdefaults standarduserdefaults] ObjectF orkey:@ "UUID"]; Gets a value that is identified as "UUID" (id = = nil) {if ([[Uidevice Currentdevice] systemversion] Floatvalue] > 6.0) {nsstring *identi Fiernumber = [[Nsuuid UUID] uuidstring]; The API that can be used after iOS 6.0 [[nsuserdefaults standarduserdefaults] setobject:identifiernumber forkey:@ "UUID"]; 
Save As UUID [[Nsuserdefaults standarduserdefaults] synchronize]; 
} else{Cfuuidref uuid = cfuuidcreate (NULL); Cfstringref uuidstring = cfuuidcreatestring (NULL, UUID); 
ios6.0 API NSString *identifiernumber = [NSString stringwithformat:@ "%@", uuidstring]; 
[[Nsuserdefaults Standarduserdefaults] setobject:identifiernumber forkey:@ "UUID"]; 
[[Nsuserdefaults standarduserdefaults] synchronize]; 
Cfrelease (uuidstring); 
Cfrelease (UUID); 
return [[Nsuserdefaults standarduserdefaults] objectforkey@ "UUID"]; 
} return ID; }

4, get the current screen resolution information

CGRect rect = [[UIScreen mainscreen] bounds]; 
CGFloat scale = [[UIScreen mainscreen].scale]; 
CGFloat width = rect.size.width * scale; 
CGFloat height = rect.size.height * scale;

5, obtain the information of the operator

Need to import header file first

#import <CoreTelephony/CTCarrier.h> 
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

Creating objects

Cctelephonynetworkinfo *info = [[Cttelephonynetworkinfo alloc] init];

Get the name of the run business

Ctcarrier *carrier = [info subscribercellularprovider]; 
NSString *mcarrier = [NSString stringwithformat:@ "%@", [carrier Carriername]];

Get the type of the current network

iOS7 can then be obtained in the following manner. Convenient and more type

NSString *mconnecttype = [[NSString alloc] initwithformat:@ "%@", info.currentradioaccesstechnology];

Types have the following:

CTRADIOACCESSTECHNOLOGYGPRS//Between 2G and 3G, also known as 2.5G, over technology 
Ctradioaccesstechnologyedge//edge for GPRS to the third generation mobile communications, Edge commonly known 
as 2.75G CTRADIOACCESSTECHNOLOGYWCDMA 
CTRADIOACCESSTECHNOLOGYHSDPA//also known as 3.5G (3?) G) 
Ctradioaccesstechnologyhsupa//3g to 4G 
ctradioaccesstechnologycdma1x//3g 
CTRadioAccessTechnologyCDMAEVDORev0//3g Standard 
Ctradioaccesstechnologycdmaevdoreva 
Ctradioaccesstechnologycdmaevdorevb 
CTRADIOACCESSTECHNOLOGYEHRPD//Telecom uses a 3G to 4G Evolution Technology, 3.75G 
Ctradioaccesstechnologylte//near 4G

Before iOS7, Apple offered us reachability to get it.

First, import the Systemconfiguration.framework, add the downloaded Reachability.h and reachability.m into the project

reachability *reach = [reachability reachabilitywithhostname:@ "www.apple.com"]; 
switch ([reach Currentreachabilitystatus]) 
{case 
notreachable://No connection 
//do something break 
; 
Case Reachableviawifi://via WiFi connection 
//do something break 
; 
Case Reachableviawwan://via GPRS connection 
//do something break 
; 
Default: <span style= "White-space:pre" > </span>//unknown//do 
something break 
; 

6, to obtain the current signal strength

This does not seem to give an official API, but some people on the web say they can implement it with proprietary APIs, but the App store audits are as follows:

A function that uses Linux to explicitly invoke an API from a dynamic library. Include header file first #import <dlfcn.h>

(int) getsignallevel 
{ 
voidvoid *libhandle = Dlopen ("/system/library/frameworks/coretelephony.framework/ Coretelephony ", rtld_lazy);//get library handle 
int (*ctgetsignalstrength);//define a function pointer 
that matches the function that will be fetched Ctgetsignalstrength = (int (*) ()) Dlsym (Libhandle, "ctgetsignalstrength"); Gets the function 

if (ctgetsignalstrength = NULL) Return-1 of the specified name 
; 
else{ 
int level = Ctgetsignalstrength (); 
Dlclose (Libhandle); Remember to close the library return level 
} 
}

7, Equipment Vibration

Need to join Audiotoolbox framework, import header file #import <AudioToolbox/AudioToolbox.h>

Add code where vibration is needed:

Audioservicesplaysystemsound (ksystemsoundid_vibrate);

But it seems this does not support the incoming vibration time and mode, control it yourself.

8, get the information about the battery

@implementation Battermonitor//Get the current state of the battery, a total of 4 states-(nsstring*) getbatterystate {uidevice *device = [Uidevice currentde 
Vice]; 
if (device.batterystate = = Uidevicebatterystateunknown) {return @ "Unknow"; 
}else if (device.batterystate = = uidevicebatterystateunplugged) {return @ "unplugged"; 
}else if (device.batterystate = = uidevicebatterystatecharging) {return @ "charging"; 
}else if (device.batterystate = = uidevicebatterystatefull) {return @ ' full '; 
return nil; 
//Get the level of electricity, 0.00~1.00-(float) getbatterylevel {return [Uidevice currentdevice].batterylevel; 
}-(void) Getbatteryinfo {nsstring *state = Getbatterystate (); 
Float level = Getbatterylevel () *100.0; Yourcontrolfunc (state, level); Write what you want to achieve after the acquisition of power information how to deal with}//Turn on the power and battery status monitoring, similar to the function of timer-(void) didload {[[Uidevice Currentdevice] Setbatterymonitoringenabl 
E:yes]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (getbatteryinfo:) Name: 
Uidevicebatterystatedidchangenotification Object:nil];[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (getbatteryinfo:) Name: 
Uidevicebatteryleveldidchangenotification Object:nil]; [Nstimer scheduledtimerwithtimeinterval:0.5f target:self selector: @selector (getbatteryinfo:) Userinfo:nil repeats: 
YES]; } @end

9. Open a Web page in app

This is relatively simple, directly with the provided interface OpenURL can be.

NSString *url = @ "www.apple.com" 
[[uiapplication sharedapplication] Openurl:[nsurl Urlwithstring:url]];

10. Open another app in app

Opening another app can still be done by OpenURL. But there are two different situations. The first is to start the built-in applications, general telephone, browser, SMS and

Messages can be called directly and add parameters, such as

[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://10086"]; 
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "mailto://devprograms@apple.com"]; 
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "sms://10086"];

The second scenario is to open the app you've developed, which registers a URL protocol for the app that will be opened. This can be registered in the project's file info.plist.

The main actions are:

Step1. Right, select "Add Row"

Step2. Key value Select "URL Types"

Step3. Open the Item 0″, and then add a URL identifier for the key. Can be any value, but it is recommended to use "anti-domain name" (for example, "Com.fcplayer.testHello").

Step4. Add one more line under Item 0.

Step5. Select "URL schemes" as the key.

Step6. Enter your URL protocol name (e.g. "testhello://" should be written "Testhello"). If necessary, you can add more than one protocol here.

In fact, when open only need URL schemes, URL identifier is optional. If you need to transfer parameters, you can add your parameters to the URL schemes://, the format is similar to the Web page development parameters. (or the URL schemes://url identifier@ added) The key is the way to define a good deal with the receiving parameter. Then add the code where you want to open it:

NSString *url = @ "URL schemes path" 
[[uiapplication sharedapplication] Openurl:[nsurl Urlwithstring:url]];

The above is a small set to introduce iOS to get the current equipment models and other information including IPhone7 and iphone7p, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.