欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS App開發(fā)中通過UIDevice類獲取設(shè)備信息的方法

 更新時間:2016年07月05日 09:28:17   作者:琿少  
UIDevice最常見的用法就是用來監(jiān)測iOS設(shè)備的電量了,然后再實現(xiàn)電池狀態(tài)通知非常方便,除此之外還有傳感器等信息的獲取,這里我們就來總結(jié)一下iOS App開發(fā)中通過UIDevice類獲取設(shè)備信息的方法:

UIDevice提供了多種屬性、類函數(shù)及狀態(tài)通知,幫助我們?nèi)轿涣私庠O(shè)備狀況。從檢測電池電量到定位設(shè)備與臨近感應(yīng),UIDevice所做的工作就是為應(yīng)用程序提供用戶及設(shè)備的一些信息。UIDevice類還能夠收集關(guān)于設(shè)備的各種具體細(xì)節(jié),例如機(jī)型及iOS版本等。其中大部分屬性都對開發(fā)工作具有積極的輔助作用。下面的代碼簡單的使用UIDevice獲取手機(jī)屬性。

簡單示例:設(shè)備相關(guān)信息的獲取  
 NSString *strName = [[UIDevice currentDevice] name]; 
 NSLog(@"設(shè)備名稱:%@", strName);//e.g. "My iPhone" 
  
 NSString *strId = [[UIDevice currentDevice] uniqueIdentifier]; 
 NSLog(@"設(shè)備唯一標(biāo)識:%@", strId);//UUID,5.0后不可用 
  
 NSString *strSysName = [[UIDevice currentDevice] systemName]; 
 NSLog(@"系統(tǒng)名稱:%@", strSysName);// e.g. @"iOS" 
  
 NSString *strSysVersion = [[UIDevice currentDevice] systemVersion]; 
 NSLog(@"系統(tǒng)版本號:%@", strSysVersion);// e.g. @"4.0" 
  
 NSString *strModel = [[UIDevice currentDevice] model]; 
 NSLog(@"設(shè)備模式:%@", strModel);// e.g. @"iPhone", @"iPod touch" 
  
 NSString *strLocModel = [[UIDevice currentDevice] localizedModel]; 
 NSLog(@"本地設(shè)備模式:%@", strLocModel);// localized version of model 

常用方法列舉:
//獲取當(dāng)前設(shè)備單例
+ (UIDevice *)currentDevice;
//獲取當(dāng)前設(shè)備名稱
@property(nonatomic,readonly,strong) NSString    *name;              // e.g. "My iPhone"
//獲取當(dāng)前設(shè)備模式
@property(nonatomic,readonly,strong) NSString    *model;             // e.g. @"iPhone", @"iPod touch"
//獲取本地化的當(dāng)前設(shè)備模式
@property(nonatomic,readonly,strong) NSString    *localizedModel;    // localized version of model
//獲取系統(tǒng)名稱
@property(nonatomic,readonly,strong) NSString    *systemName;        // e.g. @"iOS"
//獲取系統(tǒng)版本
@property(nonatomic,readonly,strong) NSString    *systemVersion;     // e.g. @"4.0"
//獲取設(shè)備方向
@property(nonatomic,readonly) UIDeviceOrientation orientation;      
//獲取設(shè)備UUID對象
@property(nullable, nonatomic,readonly,strong) NSUUID      *identifierForVendor;
//是否開啟監(jiān)測電池狀態(tài) 開啟后 才可以正常獲取電池狀態(tài)
@property(nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled NS_AVAILABLE_IOS(3_0);  // default is NO
//獲取電池狀態(tài)
@property(nonatomic,readonly) UIDeviceBatteryState          batteryState NS_AVAILABLE_IOS(3_0); 
//獲取電量
@property(nonatomic,readonly) float                         batteryLevel NS_AVAILABLE_IOS(3_0);

設(shè)備方向的枚舉如下:
typedef NS_ENUM(NSInteger, UIDeviceOrientation) {
    UIDeviceOrientationUnknown,
    UIDeviceOrientationPortrait,            // home鍵在下
    UIDeviceOrientationPortraitUpsideDown,  // home鍵在上
    UIDeviceOrientationLandscapeLeft,       // home鍵在右
    UIDeviceOrientationLandscapeRight,      // home鍵在左
    UIDeviceOrientationFaceUp,              // 屏幕朝上
    UIDeviceOrientationFaceDown             // 屏幕朝下
};

電池狀態(tài)的枚舉如下:
typedef NS_ENUM(NSInteger, UIDeviceBatteryState) {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,   // 放電狀態(tài)
    UIDeviceBatteryStateCharging,    // 充電未充滿狀態(tài)
    UIDeviceBatteryStateFull,        // 充電已充滿
};

下面的方法關(guān)于監(jiān)測屏幕狀態(tài):
//獲取是否開啟屏幕狀態(tài)更改通知
@property(nonatomic,readonly,getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications;
//開始監(jiān)測通知
- (void)beginGeneratingDeviceOrientationNotifications;    
//結(jié)束監(jiān)測通知
- (void)endGeneratingDeviceOrientationNotifications;

下面這兩個放大與距離傳感器應(yīng)用相關(guān)
@property(nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled NS_AVAILABLE_IOS(3_0); //開啟距離傳感器
//是否觸發(fā)了距離傳感器
@property(nonatomic,readonly)                            BOOL proximityState

相關(guān)通知:
//設(shè)備方向改變時發(fā)送的通知
UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification;
//電池狀態(tài)改變時發(fā)送的通知
UIKIT_EXTERN NSString *const UIDeviceBatteryStateDidChangeNotification   NS_AVAILABLE_IOS(3_0);
//電量改變時發(fā)送的通知
UIKIT_EXTERN NSString *const UIDeviceBatteryLevelDidChangeNotification   NS_AVAILABLE_IOS(3_0);
//距離傳感器狀態(tài)改變時發(fā)送的通知
UIKIT_EXTERN NSString *const UIDeviceProximityStateDidChangeNotification NS_AVAILABLE_IOS(3_0);

相關(guān)文章

最新評論