I want to check device orientation, where my device is in Portrait mode, and app is in Landscape. But my code sometimes gives Landscape. Here is my code:
if UIDevice.current.orientation.isLandscape {
print("Landscape")
}
else {
print("Portrait")
}
This is intermittent, but it mostly happens where it goes into Landscape, even when my device is in Portrait mode. Not sure if it is giving orientation of the app or device.
orientationreturns the current orientation of your device not the orientation of the user interface of your application.This is what documentation says.
In addition to that there are more vales for the orientation like
faceUp,faceDown. So in yourif-elsestatement your are grouping every other value exceptlandscapeasportrait. Be careful this might also create some unexpected outputs.