国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS App開發中通過UIDevice類獲取設備信息的方法

2020-07-26 03:18:55
字體:
來源:轉載
供稿:網友

UIDevice提供了多種屬性、類函數及狀態通知,幫助我們全方位了解設備狀況。從檢測電池電量到定位設備與臨近感應,UIDevice所做的工作就是為應用程序提供用戶及設備的一些信息。UIDevice類還能夠收集關于設備的各種具體細節,例如機型及iOS版本等。其中大部分屬性都對開發工作具有積極的輔助作用。下面的代碼簡單的使用UIDevice獲取手機屬性。

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

常用方法列舉:
//獲取當前設備單例
+ (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);

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

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

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

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

相關通知:
//設備方向改變時發送的通知
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);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天门市| 东源县| 阿拉善左旗| 芮城县| 巴林左旗| 亳州市| 嫩江县| 枞阳县| 靖远县| 滦南县| 浦北县| 广西| 常德市| 洪雅县| 衡水市| 麻城市| 双柏县| 饶阳县| 洛川县| 扎兰屯市| 高碑店市| 杭州市| 澜沧| 白河县| 洛阳市| 菏泽市| 漾濞| 瑞昌市| 休宁县| 皋兰县| 新沂市| 东方市| 丹东市| 阳朔县| 伊通| 西贡区| 视频| 紫阳县| 新干县| 长阳| 乳山市|