iOS 通过UIDevice 获取系统相关属性
2016-04-25 11:12
513 查看
- (void)viewDidLoad
{
[super viewDidLoad];
// 操作系统
NSString * osName =[[UIDevice currentDevice]systemName];
// 操作系统版本
NSString * systemVersion =[[UIDevice currentDevice]systemVersion];
NSLog(@"os =%@ ",osName);
NSLog(@"version =%@",systemVersion);
// IOS设备模型
NSString *iosmodel =[[UIDevice currentDevice]model];
NSLog(@"%@",iosmodel);
// 电量的范围从0.0(全部泻出)-1.0(100%)在访问这个属性之前要确保batterymonitoring这个属性是可用的
// 电量查询
float batteryLevel = [UIDevice currentDevice].batteryLevel;
NSLog(@"%f",batteryLevel);
// 检测电池状态
UIDeviceBatteryState batteryState = [[UIDevice currentDevice]batteryState];
// 有如下几个状态
// UIDeviceBatteryStateUnknown 0 未识别 0
// UIDeviceBatteryStateUnplugged, 充电中 1
// UIDeviceBatteryStateCharging, 少于100% 2
// UIDeviceBatteryStateFull, 充满了 3
NSLog(@"%d",batteryState);
// 检测是否支持多任务处理
BOOL support =[[UIDevice currentDevice]isMultitaskingSupported];
if(support)
{
NSLog(@"supportmultiTask");
}
else
{
NSLog(@"don,t supportmultiTask");
}
// 检测当前设备方向是否改变
// YES 方向改变
// NO 方向未改变
BOOL status =[UIDevice currentDevice].generatesDeviceOrientationNotifications ;
NSLog(@"%d",status);
// 开始改变设备方向 如果需要在改变方向的时候处理一些事情可以重写这个方法
// [[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications ];
// 结束改变设备方向 同上
// [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
// 临近状态检测
// 当你的身体靠近iPhone而不是触摸的时候,iPhone将会做出反应。(需要一定的面的影射,约5mm左右的时候就会触发)
// YES 临近 消息触发
// NO
BOOL proximityState = [[UIDevice currentDevice]proximityState];
NSLog(@"%d",proximityState);
UIDevice *device = [UIDevice currentDevice ];
device.proximityMonitoringEnabled=YES; // 允许临近检测
// 临近消息触发
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximityChanged:)
name:UIDeviceProximityStateDidChangeNotification object:device];
}
// 临近手机消息触发
- (void) proximityChanged:(NSNotification *)notification {
UIDevice *device = [notification object];
NSLog(@"In proximity:%i",device.proximityState);
if(device.proximityState==1){
//do something
}
}
{
[super viewDidLoad];
// 操作系统
NSString * osName =[[UIDevice currentDevice]systemName];
// 操作系统版本
NSString * systemVersion =[[UIDevice currentDevice]systemVersion];
NSLog(@"os =%@ ",osName);
NSLog(@"version =%@",systemVersion);
// IOS设备模型
NSString *iosmodel =[[UIDevice currentDevice]model];
NSLog(@"%@",iosmodel);
// 电量的范围从0.0(全部泻出)-1.0(100%)在访问这个属性之前要确保batterymonitoring这个属性是可用的
// 电量查询
float batteryLevel = [UIDevice currentDevice].batteryLevel;
NSLog(@"%f",batteryLevel);
// 检测电池状态
UIDeviceBatteryState batteryState = [[UIDevice currentDevice]batteryState];
// 有如下几个状态
// UIDeviceBatteryStateUnknown 0 未识别 0
// UIDeviceBatteryStateUnplugged, 充电中 1
// UIDeviceBatteryStateCharging, 少于100% 2
// UIDeviceBatteryStateFull, 充满了 3
NSLog(@"%d",batteryState);
// 检测是否支持多任务处理
BOOL support =[[UIDevice currentDevice]isMultitaskingSupported];
if(support)
{
NSLog(@"supportmultiTask");
}
else
{
NSLog(@"don,t supportmultiTask");
}
// 检测当前设备方向是否改变
// YES 方向改变
// NO 方向未改变
BOOL status =[UIDevice currentDevice].generatesDeviceOrientationNotifications ;
NSLog(@"%d",status);
// 开始改变设备方向 如果需要在改变方向的时候处理一些事情可以重写这个方法
// [[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications ];
// 结束改变设备方向 同上
// [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
// 临近状态检测
// 当你的身体靠近iPhone而不是触摸的时候,iPhone将会做出反应。(需要一定的面的影射,约5mm左右的时候就会触发)
// YES 临近 消息触发
// NO
BOOL proximityState = [[UIDevice currentDevice]proximityState];
NSLog(@"%d",proximityState);
UIDevice *device = [UIDevice currentDevice ];
device.proximityMonitoringEnabled=YES; // 允许临近检测
// 临近消息触发
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximityChanged:)
name:UIDeviceProximityStateDidChangeNotification object:device];
}
// 临近手机消息触发
- (void) proximityChanged:(NSNotification *)notification {
UIDevice *device = [notification object];
NSLog(@"In proximity:%i",device.proximityState);
if(device.proximityState==1){
//do something
}
}
相关文章推荐
- 个性化 UIAlertController
- 【CodeForces 618B 】Guess the Permutation(水题)
- WM_CLOSE,WM_QUIT,WM_DESTROY消息的区别
- 解决StoryBoard上cell上定义的view的背景点击后不显示的问题(其中用uiview 当作线的时候最多遇到,会不显示线 而出现不流畅问题)
- UICollectionView 基础篇
- LeetCode 64/62/63. Minimum Path Sum/ Unique Paths i, ii
- UILabel文字重叠
- Quick Sort
- 我写了一个java实体类,implements了Serializable接口,然后我如何让serialversionUID自动生成
- hdu 3836 Equivalent Sets //tarjan+缩点
- 2016.04.25,英语,《Vocabulary Builder》Unit 18
- Mavlink地面站编写之五-Mission Planner中ProgressReporterDialogue和读串口线程serialreaderthread的分析
- JAVA--建造者模式(Builder)--设计模式四
- Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'x/info.plist'
- 从为什么String=String谈到StringBuilder和StringBuffer
- pip自动生成requirements.txt依赖关系清单
- UITableView取消多余的表格线条
- 关于UIScrollView不能响应UITouch事件的解决办法
- 232. Implement Queue using Stacks
- Windows 10年度更新Anniversary Update预览版开始推送,版本号Build 14328