码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 获取设备信息

时间:2014-10-10 17:54:04      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   sp   on   cti   log   ad   ef   

- (void)viewDidLoad

{

    [super viewDidLoad];

 

    //获取当前设备操作系统及版本

    NSString *systemName =[[UIDevice currentDevice]systemName];

    NSString *system  =[[UIDevice currentDevice]systemVersion];

    NSLog(@"%@ %@",systemName,system);

    

    //获取运行应用设备

    NSString *hardware  =[[UIDevice currentDevice]model];

    NSLog(@"%@",hardware);

    

    //设备电池电量0-1.0

    float electricQuantity =  [UIDevice currentDevice].batteryLevel;

    NSLog(@"%f",electricQuantity);

    

    /*

     设备电池电量状态

     typedef NS_ENUM(NSInteger, UIDeviceBatteryState) {

     UIDeviceBatteryStateUnknown,

     UIDeviceBatteryStateUnplugged,   // on battery, discharging

     UIDeviceBatteryStateCharging,    // plugged in, less than 100%

     UIDeviceBatteryStateFull,        // plugged in, at 100%

     };              // available in iPhone 3.0

     

     */

    UIDeviceBatteryState state = [[UIDevice currentDevice]batteryState];

    NSLog(@"%d",state);

    

    //是否支持多任务处理

    BOOL muchTask =[[UIDevice currentDevice]isMultitaskingSupported];

    NSLog(@"%d",muchTask);

    

    //设备方向改变 YES改变 NO未变

    BOOL direction =[UIDevice currentDevice].generatesDeviceOrientationNotifications ;

    NSLog(@"%d",direction);

    

    //改变设备方向

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications ];

    

    //改变方向结束

    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    

    //靠近状态检测 当你靠近iPhone而不是触摸的时候,iPhone将会做出反应。 YES临近消息触发

    BOOL isYes = [[UIDevice currentDevice] proximityState];

    NSLog(@"%d",isYes);

    

    UIDevice *device =  [UIDevice currentDevice];

    device.proximityMonitoringEnabled=YES; //允许临近检测

    //触发

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(proximityClick:)

                                                 name:UIDeviceProximityStateDidChangeNotification object:device];

}

 

//临近消息触发

- (void) proximityClick:(NSNotification *)notification {

    UIDevice *device = [notification object];

    NSLog(@"In proximity:%i",device.proximityState);

    if(device.proximityState==1){

        

        

    }

}

 

//设备方向改变

- (void)beginGeneratingDeviceOrientationNotifications

{

    NSLog(@"begin...");

}

 

//方向改变结束

- (void)endGeneratingDeviceOrientationNotifications

{

    NSLog(@"over...");

}

 

iOS 获取设备信息

标签:io   os   ar   sp   on   cti   log   ad   ef   

原文地址:http://www.cnblogs.com/iOS-xiao-lei/p/4015857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!