1、获取设备信息
[[UIDevicecurrentDevice]name];//设备的名称 李四的 iphone
[[UIDevicecurrentDevice]systemName];//系统的名称 iPhone OS
[[UIDevicecurrentDevice]systemVersion];//设备系统的版本号 5.1.1、6.0
[[UIDevicecurrentDevice]model];//设备的型号 iPad、iphone、ipod 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刚好相反。