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=isDosBat target=_blank class=infotextkey>BatteryMonitoringEnabled) BOOL DosBat target=_blank class=infotextkey>BatteryMonitoringEnabled NS_AVAILABLE_IOS(3_0); // default is NO
//獲得電池狀況
@property(nonatomic,readonly) UIDeviceDosBat target=_blank class=infotextkey>BatteryState 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);
【iOS App開辟中經由過程UIDevice類獲得裝備信息的辦法】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!