0

I'm trying to detect a Today Extension's orientation, but none of the typical methods seem to work.

I've tried the following:

[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft;

[UIDevice currentDevice]orientation] = UIDeviceOrientationLandscapeLeft;

I've even tried using CMMotionManger.

Thanks for your help.

user1752054
  • 372
  • 4
  • 17

2 Answers2

0

Seems like there is no bullet-proof solution for Extensions.

Look at this answer for possible workaround - https://stackoverflow.com/a/26023538/2797141

Community
  • 1
  • 1
xZenon
  • 655
  • 6
  • 18
-1

The orientation can't be detected by any normal means. However, every time the widget opens it calls "viewDidLoad". So, in viewDidLoad, detect screen width & height thusly and determine your own orientation.

int startOrientation;
int screenWidth = self.view.frame.size.width; //Screen Width
int screenHeight = self.view.frame.size.height; // Screen Height;

if (screenWidth > screenHeight) {
    startOrientation = @"landscape";
} else {
    startOrientation = @"portrait";
}
Marsman
  • 825
  • 1
  • 10
  • 20
  • This doesn't work. Consider the case of a container view...In that situation, width could easily be more than height while you're screen is in portrait. – Jake Aug 31 '16 at 02:46