iOS 获取设备信息

- (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...");

}

 

转载于:https://www.cnblogs.com/iOS-xiao-lei/p/4015857.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值