A method of acquiring device information via Uidevice class in IOS app development _ios

Source: Internet
Author: User
Tags touch unique id uuid

Uidevice provides a wide range of properties, class functions, and status notifications to help us understand the status of the equipment. From detecting battery power to locating devices and proximity sensors, Uidevice's job is to provide some information about users and devices to the application. The Uidevice class can also collect specific details about the device, such as models and iOS versions. Most of these attributes have a positive effect on development work. The following code simply uses Uidevice to get phone properties.

Simple example: acquisition of device-related information
 nsstring *strname = [[Uidevice currentdevice] name]; 
 nslog (@ "Device name:%@", strName);//e.g. "My IPhone " 
  
 nsstring *strid = [[Uidevice currentdevice] uniqueidentifier]; 
&nbs P NSLog (@ "Device unique ID:%@", Strid)//uuid,5.0 unavailable  
  
 nsstring *strsysname = [[Uidevice Currentdevice] systemname]; 
 nslog (@ "system name:%@", strsysname);//e.g. @ "IOS"  
  
& nbsp NSString *strsysversion = [[Uidevice currentdevice] systemversion]; 
 nslog (@ system version number:%@ ", strSysVersion) ;//e.g. @ "4.0"  
  
 nsstring *strmodel = [[Uidevice currentdevice] model]; 
  ; NSLog (@ "Device mode:%@", strmodel)//e.g @ "iPhone" @ "ipod Touch"  
  
 nsstring *strlocmodel = [ Uidevice Currentdevice] localizedmodel]; 
 nslog (@ "Local device mode:%@", strlocmodel);//localized version of model 

Common methods to enumerate:
Get the current device single example
+ (Uidevice *) Currentdevice;
Get Current device name
@property (Nonatomic,readonly,strong) NSString *name; e.g. "My IPhone"
Get current device mode
@property (Nonatomic,readonly,strong) NSString *model; e.g @ "iPhone", @ "ipod touch"
Get the localized current device mode
@property (Nonatomic,readonly,strong) NSString *localizedmodel; Localized version of Model
Get system Name
@property (Nonatomic,readonly,strong) NSString *systemname; e.g. @ "IOS"
Get System version
@property (Nonatomic,readonly,strong) NSString *systemversion; e.g. @ "4.0"
Get device Orientation
@property (nonatomic,readonly) uideviceorientation orientation;
Get device UUID Object
@property (Nullable, Nonatomic,readonly,strong) Nsuuid *identifierforvendor;
Whether the battery status can be obtained when the battery status is turned on
@property (nonatomic,getter=isbatterymonitoringenabled) BOOL batterymonitoringenabled Ns_available_ios (3_0); Default is NO
Get battery status
@property (nonatomic,readonly) uidevicebatterystate batterystate Ns_available_ios (3_0);
Get the electricity
@property (nonatomic,readonly) float batterylevel ns_available_ios (3_0);

The

device direction is enumerated as follows:
typedef ns_enum (Nsinteger, uideviceorientation) {
    Uideviceorientationunknown,
    uideviceorientationportrait,            //Home key in the next
    Uideviceorientationportraitupsidedown,  //Home key on
    uideviceorientationlandscapeleft,      // Home key on right
    uideviceorientationlandscaperight,     //Home key on left
    uideviceorientationfaceup,              //Screen facing up
    uideviceorientationfacedown             //Screen facing down
};

The battery status is enumerated as follows:
typedef NS_ENUM(NSInteger, UIDeviceBatteryState) {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,   // 放电状态
    UIDeviceBatteryStateCharging,    // 充电未充满状态
    UIDeviceBatteryStateFull,        // 充电已充满
};

The following method is about monitoring screen status:
//获取是否开启屏幕状态更改通知
@property(nonatomic,readonly,getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications;
//开始监测通知
- (void)beginGeneratingDeviceOrientationNotifications;    
//结束监测通知
- (void)endGeneratingDeviceOrientationNotifications;

The following two amplifiers are related to the distance sensor application
@property(nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled NS_AVAILABLE_IOS(3_0); //开启距离传感器
//是否触发了距离传感器
@property(nonatomic,readonly)                            BOOL proximityState

Related notices:
//设备方向改变时发送的通知
UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification;
//电池状态改变时发送的通知
UIKIT_EXTERN NSString *const UIDeviceBatteryStateDidChangeNotification   NS_AVAILABLE_IOS(3_0);
//电量改变时发送的通知
UIKIT_EXTERN NSString *const UIDeviceBatteryLevelDidChangeNotification   NS_AVAILABLE_IOS(3_0);
//距离传感器状态改变时发送的通知
UIKIT_EXTERN NSString *const UIDeviceProximityStateDidChangeNotification NS_AVAILABLE_IOS(3_0);

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.