記錄UIDevice的屬性和方法
UIDevice *device = [UIDevice currentDevice];
//屬性都是readOnly
//設(shè)備名稱 iPhone 11
NSLog(@"%@",device.name);
//系統(tǒng)名稱 iOS
NSLog(@"%@",device.systemName);
//系統(tǒng)版本 13
NSLog(@"%@",device.systemVersion);
//設(shè)備類型 iPhone
NSLog(@"%@",device.model);
//設(shè)備類型的本地實例化名稱
NSLog(@"%@",device.localizedModel);
//當前設(shè)備上使用的接口樣式
//Unspecified未指定/Phone手機/Pad/TV/CarPlay 5種方式
NSLog(@"%ld",(long)device.userInterfaceIdiom);
//設(shè)備的UUID
NSLog(@"%@",device.identifierForVendor);
//返回設(shè)備的物理方向
//橫屏/豎屏 / 設(shè)備面朝上/朝下 等
NSLog(@"%ld",(long)[device orientation]);
//開始獲取設(shè)備的物理方向
[device beginGeneratingDeviceOrientationNotifications];
//設(shè)備接受者是否開啟獲取設(shè)備方向的通知
NSLog(@"%d",[device isGeneratingDeviceOrientationNotifications]);
//結(jié)束獲取設(shè)備的物理方向
[device endGeneratingDeviceOrientationNotifications];
//設(shè)備的電池電量
NSLog(@"%.f",device.batteryLevel);
//是否啟用電池監(jiān)視(是)或不(否)
NSLog(@"%d",device.isBatteryMonitoringEnabled);
//設(shè)備電池狀態(tài)
//未知、不插電剂桥、插電篡石、滿電 4種
NSLog(@"%ld",(long)device.batteryState);
//是否接近傳感器
//如果沒有接近,總是返回NO
NSLog(@"%d",device.proximityState);
//是否監(jiān)聽傳感器狀態(tài)改變
NSLog(@"%d",device.isProximityMonitoringEnabled);
//僅當屏幕上出現(xiàn)啟用輸入視圖且用戶啟用了輸入單擊時使套,才播放單擊罐呼。暫未用到
[device playInputClick];
//監(jiān)聽通知名稱
//UIDeviceOrientationDidChangeNotification 物理方向發(fā)生改變
//UIDeviceBatteryStateDidChangeNotification 電池??狀態(tài)發(fā)生改變
//UIDeviceBatteryLevelDidChangeNotification 電池電量發(fā)生改變
//UIDeviceProximityStateDidChangeNotification 傳感器狀態(tài)發(fā)生改變
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondsToDeviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondsToDeviceBatteryStateDidChange:) name:UIDeviceBatteryStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondsToDeviceBatteryLevelDidChange:) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondsToDeviceProximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil];
其中,下面這個監(jiān)聽物理方向改變的通知有一個坑
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondsToDeviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];