"1" Determines whether it is a horizontal screen:
BOOL B=uideviceorientationislandscape ([Uidevice currentdevice].orientation);
Get device uniqueidentifier:
[Uidevice Currentdevice].uniqueidentifier;
But in iOS5, it has been discarded.
http://kensou.blog.51cto.com/3495587/655083
[[Uidevice Currentdevice] systemName]; [[Uidevice Currentdevice] Systemversion];//os version[[uidevice currentdevice] uniqueidentifier]; [[Uidevice Currentdevice] model]; [[Uidevice Currentdevice] name];
True on-Machine results:
System Name:iphone OS
System version:4.2.1
Unique id:9b5ded78d5fa0ac96250f8b4af0e46f40b96ea6d
Model:iphone
Name: "Wwk" of the IPhone
Results on Simulator:
System Name:iphone OS
System version:4.2
Unique id:21ffe0ff-429b-5d0b-96d2-eadca3203260
Model:iphone Simulator
Name:iphone Simulator
This identifier is generated by Uniqueidentifier:iphone, which applies an internal hashing algorithm to several hardware identifiers and device serial numbers.
"2" battery event notification and battery status: The battery level is a floating point value, from 0.0 to full discharge, to 1.0 fully charged.
[nslog:@ "Battery Level:%0.2f%", [[Uidevice Currentdevice] batterylevel] * 100]; Nsarray *statearray = [Nsarray arraywithobjects: @ "Unknown", @ "not plugged to a charging source", @ "charging", @ "full", NIL]; [nslog:@ "Battery State:%@", [Statearray objectatindex:[[uidevice Currentdevice] batterystate]];
For more device information: Use Sysctlbyname (), sysctl () standard UNIX functions.
Some device information constants are provided in Sys/sysctl.h. Be aware that you want # include <sys/socket.h> first.
Specific reference to "Cheats 2" 14.3 regain more device information.
The Hw.machine value, the first-generation iphone is (iphone1,1), the iphone3g is (iphone1,2), IPHONE3GS is (iphone2,1), and the simulator is x86_64.
"3". Sensor.
When the proximity sensor is enabled, it detects if there is a large object in front of it, and if so, it turns off the screen and gives a general notification. When the obstacle is removed, the screen is reopened. This prevents the misuse of the ear touch button during the notification process.
Also prevent some protective cases from affecting the sensor work.
[Uidevice Currentdevice].proximitymonitoringenabled=yes; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (handlestatechange:) name:@ " Uideviceproximitystatedidchangenotification "Object:nil";
"4" acceleration.
On the speed of measurement, the iphone provides 3 onboard sensors that measure acceleration along the 3-direction xyz of the iphone's vertical axis, which represents the force that affects the iphone.
[[Uiaccelerometer Sharedaccelerometer] setdelegate:self];//uiaccelerometerdelegate -(void) Accelerometer: ( Uiaccelerometer *) Accelerometer didaccelerate: (uiacceleration *) acceleration{ float xx =-[acceleration x]; float yy = [acceleration y]; float angle = atan2 (yy, xx); [Arrow settransform:cgaffinetransformmakerotation (angle)];}
"5" Detection device direction: horizontal or vertical.
[[Uidevice Currentdevice] begingeneratingdeviceorientationnotifications]; Not actually required but a good idea in case Apple changes this [[Nsnotificationcenter Defaultcenter] Addobserver: Self selector: @selector (orientationchanged:) name:uideviceorientationdidchangenotification object:nil];// Rewrite shouldautorotatetointerfaceorientation-(BOOL) shouldautorotatetointerfaceorientation in Viewcontroller: ( uiinterfaceorientation) anorientation{ return (anorientation = = Uideviceorientationportrait | | Anorientation = = Uideviceorientationlandscaperight | | Anorientation = = Uideviceorientationlandscapeleft | |); iphone is not recommended for use with uideviceorientationportraitupsizedown}-(void) orientationchanged: (ID) sender{ NSLog (@ " Orientation changed to%@ ", [Uidevice currentdevice].orientationstring);//Current device orientation}// Two built-in macro-assisted judgment direction uideviceorientationisportrait (anorientation) uideviceorientationislandscape (anorientation)
"6" Shaking detection shakedetection.
Response chain: A response chain provides a hierarchical object that, if received by an object at the beginning, is no longer passed down, otherwise it continues to pass down.
The object is usually passed [self becomefirstresponder]; declares itself to be the first responder. [self resignfirstresponder]; Declaration exits first Responder. The first responder receives all motion and touch events.
-(BOOL) Canbecomefirstresponder {return YES;}
There are 3 motion callback functions that can be overridden, which are defined in Uiresponder:
-(void) Motionbegan: (uieventsubtype) Motion withevent: (uievent *) event -(void) motionended: (Uieventsubtype) Motion withevent: (uievent *) event
"7" Disk space
Nsfilemanager *FM = [Nsfilemanager Defaultmanager]; Nsdictionary *fattributes = [FM filesystemattributesatpath:nshomedirectory ()]; System space:[[fattributes objectforkey:nsfilesystemsize] longlongvalue]; System free space: [[Fattributes objectforkey:nsfilesystemfreesize] longlongvalue];
"8" itunes determines whether a program can be downloaded to a specified device and run correctly through a list of device features listed in Info.plist.
"9" has a version macro definition in the AVAILABILITY.h file, for example: __iphone_4_2
Is this OS version or SDK version, or are they the same?
Http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/Availability.h
"10"
nsstring* Udid=[[uidevice Currentdevice] uniqueidentifier]; return udid;
"11"
Instead, a button is used in the topmost layer to respond to the Click event */else { nsstring* systemversion=[[uidevice currentdevice] systemversion]; float floatversion=[systemversion Floatvalue]; NSLog (@ "systemversion:%@,floatversion:%f", systemversion,floatversion); if (floatversion<5.0) { //in ios5, each layer UIView responds to touchesended, so iOS5 does not have to be raised here. ret=[(viewgroupwrap*) isuperviewwrap Handletouch]; } } */
"12" coding different ways to differentiate iphone ipod & ipad
(1) Use UI_USER_INTERFACE_IDIOM () to differentiate
Ui_user_interface_idiom () = = Uiuserinterfaceidiompad //ipadui_user_interface_idiom () = = Uiuserinterfaceidiomphone //iphone
(2) using Uidevice.model to differentiate
NSString *devicetype = [Uidevice currentdevice].model; if ([DeviceType isequaltostring:@ "IPhone"]) { //iphone } else if ([DeviceType isequaltostring:@ "IPod Touch "]) { //ipod touch } else { //ipad }
(3) Use a function sysctlbyname of the system to get the device name
-(NSString *) platformstring{size_t size; Sysctlbyname ("Hw.machine", NULL, &size, NULL, 0); Char *machine = malloc (size); Sysctlbyname ("Hw.machine", Machine, &size, NULL, 0); NSString *platform = [NSString stringwithutf8string:machine]; 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:@ "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:@ "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:@ "i386"]) return @ "Simulator"; return @ "";}
Reference http://hi.baidu.com/songxiaoweiss/blog/item/c78162f869fc148c58ee9028.html
"13" About getting IMSI number
Coretelephony.framework,
Header file Contents
extern nsstring* c*****t Kctsmsmessagereceivednotification;extern nsstring* c*****t Kctsmsmessagereplacereceivednotification;extern nsstring* c*****t Kctsimsupportsimstatusnotinserted;extern nsstring* c*****t Kctsimsupportsimstatusready; ID cttelephonycentergetdefault (void); void Cttelephonycenteraddobserver (id,id,cfnotificationcallback,nsstring*, Void*,int); void Cttelephonycenterremoveobserver (id,id,nsstring*,void*); int ctsmsmessagegetunreadcount (void); int ctsmsmessagegetrecordidentifier (void * msg); NSString * Ctsimsupportgetsimstatus (); Get SIM card status, kctsimsupportsimstatusnotinserted means no SIM card NSString * ctsimsupportcopymobilesubscriberidentity (); Get IMSI number ID ctsmsmessagecreate (void* unknow/*always 0*/,nsstring* number,nsstring* text); void * Ctsmsmessagecreatereply (void* unknow/*always 0*/,void * forwardto,nsstring* text); void* ctsmsmessagesend (ID server,id msg); NSString *ctsmsmessagecopyaddress (void *, void *); NSString *ctsmsmessagecopytext (void *, void *);
Call Ctsimsupportcopymobilesubscriberidentity can successfully get to the IMSI number
Use Performselector to escape the apple test.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"iOS Development Series" Uidevice device information