[[UIDevice currentDevice] orientation] is not working for iPad


Today I face a problem in developing my app for iPad. I am checking the current orientation of my device using the following function and checking weather it is in Portrait or Landscape mode. This was working for iPhone 5.1 simulator properly but when I am checking this for iPad Simulator 5.1 it’s not working.

-(void) checkCurrentOrientation
{
UIDeviceOrientation interfaceOrientation= [[UIDevice currentDevice] orientation];
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
NSLog(@"Portrait");
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
NSLog(@"Landscape");
}
else {
NSLog(@"Not Found");
}
}

I call this function from my ViewDidLoad function and it is printing Not Found for iPad.

This is only working when device is changing its orientation. Now if we need to do something in our viewDidLoad function according to device orientation for iPad then its not going to work in this way.
I just find a way to solve this. Instead of using [[UIDevice currentDevice] orientation] I am taking the orientation of status bar and this is working for me.

Here is the code for that

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation== UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"Portrait");
}
else if(orientation== UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
NSLog(@"Landscape");
}

Thanks.

Any kinds of suggestion is appreciated.

Advertisements

About Razib Chandra Deb

I completed my BSc in CSE from CSE Department of KUET. Currently I am working as a Software Engineer in Samsung R&D Institute Bangladesh(SRBD). I am interested in image processing.
This entry was posted in iPhone and tagged , , , , , , . Bookmark the permalink.

One Response to [[UIDevice currentDevice] orientation] is not working for iPad

  1. kuttumiah says:

    Nice writing. Well said, Razib 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s