How to get device current orientation in an App Extension, I have tried below two methods but no success.
It always return UIDeviceOrientationUnknown
<
I have done in my custom keyboard extension,Hope It will help you..
In order to update your custom keyboard when the orientation changes, override viewDidLayoutSubviews in the UIInputViewController. In another word, we can say that viewDidLayoutSubviews always called when rotation done.
In keyboard extension we're unable to use traditional flow as we usually used:
[UIApplication sharedApplication] statusBarOrientation]
So to detect current orientation, I used following code: In Objc :
if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height){
// Portrait Orientation
}
else{
//Landscape Orientation
}
And in swift4, you can use this:
if UIScreen.main.bounds.size.width > UIScreen.main.bounds.size.height {
//portrait Orientation
}
else
{
//landscape Orientation
}