Please, help me. I have methods:
-(void) getCurrentOrientation{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation == UIInterfaceOrientationPortrait){
NSLog(@"portrait");
} else if(orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"LandscapeRight");
} else if(orientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"LandscapeLeft");
}
}
but when i call this getCurrentOrientation throw viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
[self getCurrentOrientation];
}
NSLog is empty. Whats wrong ?
I also try
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if ( ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait)) {
NSLog(@"portrait");
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
NSLog(@"LandscapeRight");
}
}
but that varint also empty.
I need to know in which ORIENTATION user launch APP!
Please, give me any advice.
Your code is absolutely correct and there is no problem.
This statement only works in original devices.
However you want to check in simulator you can check as
Update:
I have tested for you in both device and simulator. Initially it would show portrait only in viewDidLoad though you will keep device in landscape. First Controller will look into shouldAutoRotate method.
You should not depend on
viewDidLoadfor initial orientation. You should depend on shouldAutorotate method initially for exact orientation.