IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (真机亲测可用)
2014-09-11 12:02
489 查看
http://blog.csdn.net/kolnick/article/details/22334749
- (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
}
}
- (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
}
}
相关文章推荐
- IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (真机亲测可用)
- IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (真机亲测可用)
- IOS设备 UIDevice 获取操作系统 版本 电量 临近手机触发消息检测 (转载)
- iOS 获取手机的型号,系统版本,设备名称等
- 【代码笔记】iOS-手机版本号,机型,操作系统版本,设备唯一标识符
- ios获取手机型号、系统版本、设备唯一标识符、手机运营商等
- iOS开发-Swift获取手机设备信息(UIDevice)
- iOS开发-Swift获取手机设备信息(UIDevice)
- 【代码笔记】iOS-手机版本号,机型,操作系统版本,设备唯一标识符
- ios获取手机型号、系统版本、设备唯一标识符、手机运营商等
- iOS_获取设备型号、手机系统版本
- iOS开发-Object-C获取手机设备信息(UIDevice)
- iOS开发-Object-C获取手机设备信息(UIDevice)
- iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)
- 获取IOS设备的类型和系统版本
- 获取ios设备电量
- iOS学习中获取手机信息(UIDevice、NSBundle、NSLocale)
- iOS 获取手机的型号,系统版本,软件名称,软件版本
- IOS获取手机设备所有应用
- iOS 获取手机的型号,系统版本,软件名称,软件版本