//獲取當前設備單例 + (UIDevice *)currentDevice; //獲取當前設備名稱 @property(nonatomic,readonly,strong) NSString *name; // e.g. "My iPhone" //獲取當前設備模式 @property(nonatomic,readonly,strong) NSString *model; // e.g. @"iPhone", @"iPod touch" //獲取本地化的當前設備模式 @property(nonatomic,readonly,strong) NSString *localizedModel; // localized version of model //獲取系統名稱 @property(nonatomic,readonly,strong) NSString *systemName; // e.g. @"iOS" //獲取系統版本 @property(nonatomic,readonly,strong) NSString *systemVersion; // e.g. @"4.0" //獲取設備方向 @property(nonatomic,readonly) UIDeviceOrientation orientation; //獲取設備UUID對象 @property(nullable, nonatomic,readonly,strong) NSUUID *identifierForVendor; //是否開啓監測電池狀態 開啓後 才能夠正常獲取電池狀態 @property(nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled NS_AVAILABLE_IOS(3_0); // default is NO //獲取電池狀態 @property(nonatomic,readonly) UIDeviceBatteryState batteryState NS_AVAILABLE_IOS(3_0); //獲取電量 @property(nonatomic,readonly) float batteryLevel NS_AVAILABLE_IOS(3_0);
設備方向的枚舉以下:ide
typedef NS_ENUM(NSInteger, UIDeviceOrientation) { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, // home鍵在下 UIDeviceOrientationPortraitUpsideDown, // home鍵在上 UIDeviceOrientationLandscapeLeft, // home鍵在右 UIDeviceOrientationLandscapeRight, // home鍵在左 UIDeviceOrientationFaceUp, // 屏幕朝上 UIDeviceOrientationFaceDown // 屏幕朝下 };
電池狀態的枚舉以下:atom
typedef NS_ENUM(NSInteger, UIDeviceBatteryState) { UIDeviceBatteryStateUnknown, UIDeviceBatteryStateUnplugged, // 放電狀態 UIDeviceBatteryStateCharging, // 充電未充滿狀態 UIDeviceBatteryStateFull, // 充電已充滿 };
下面的方法關於監測屏幕狀態:spa
//獲取是否開啓屏幕狀態更改通知 @property(nonatomic,readonly,getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications; //開始監測通知 - (void)beginGeneratingDeviceOrientationNotifications; //結束監測通知 - (void)endGeneratingDeviceOrientationNotifications;
下面這兩個放大與距離傳感器應用相關,可參考:http://my.oschina.net/u/2340880/blog/544341..net
@property(nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled NS_AVAILABLE_IOS(3_0); //開啓距離傳感器 //是否觸發了距離傳感器 @property(nonatomic,readonly) BOOL proximityState
相關通知:code
//設備方向改變時發送的通知 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);
專一技術,熱愛生活,交流技術,也作朋友。對象
——琿少 QQ羣:203317592blog