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

}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。