获取设备信息

1、获取设备信息

[[UIDevicecurrentDevice]name];//设备的名称 李四的 iphone

[[UIDevicecurrentDevice]systemName];//系统的名称  iPhone OS

    [[UIDevicecurrentDevice]systemVersion];//设备系统的版本号  5.1.16.0

[[UIDevicecurrentDevice]model];//设备的型号   iPadiphoneipod touch

[[UIDevicecurrentDevice]localizedModel];//本地化的模型  iPad

[[UIDevicecurrentDevice]userInterfaceIdiom];//获取app运行的设备类型

[[UIDevicecurrentDevice]identifierForVendor];//获取UUID

[[UIDevicecurrentDevice]batteryLevel];//电池电量

2、UIDeviceOrientation是设备的方向,只能读取不能设置,支持6个方向

设备的方向:

typedef NS_ENUM(NSInteger, UIDeviceOrientation) {

    UIDeviceOrientationUnknown,

    UIDeviceOrientationPortrait,           // Device oriented vertically, home button on the bottom

    UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top

    UIDeviceOrientationLandscapeLeft,      // Device oriented horizontally, home button on the right

    UIDeviceOrientationLandscapeRight,     // Device oriented horizontally, home button on the left

    UIDeviceOrientationFaceUp,             // Device oriented flat, face up

    UIDeviceOrientationFaceDown            // Device oriented flat, face down

};

实现:

-(void) viewDidLoad {

     // Request to turn on accelerometer and begin receiving accelerometer events

     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

}

 

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

     // Respond to changes in device orientation

NSLog(@"Orientation changed to %zi", [[UIDevicecurrentDevice]orientation]);//当前设备方向

}


-(void) viewDidDisappear {

     // Request to stop receiving accelerometer events and turn off accelerometer

     [[NSNotificationCenter defaultCenter] removeObserver:self];

     [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

}

3、UIInterfaceOrientation是软件的方向,可以读取可以设置

app的方向:

typedefNS_ENUM(NSInteger, UIInterfaceOrientation) {

    UIInterfaceOrientationPortrait           =UIDeviceOrientationPortrait,

    UIInterfaceOrientationPortraitUpsideDown =UIDeviceOrientationPortraitUpsideDown,

    UIInterfaceOrientationLandscapeLeft      =UIDeviceOrientationLandscapeRight,

    UIInterfaceOrientationLandscapeRight     =UIDeviceOrientationLandscapeLeft

};

注意:UIInterfaceOrientation的横屏的左边和右边跟UIDeviceOrientation刚好相反。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值