Get UIInterfaceOrientation when just one is supported - ipad

I have an iPad App that supports just one orientation (landscapeRight). Unless I want to get the current orientation of the device to display something if the device is held the wrong way.
How can I do this? I tried like 6 different methods of determining the orientation. But all of them just determine the interface orientation, not the device orientation.
Thanks for advice, with kind regards, Julian

Related

How do I programmatically control device orientation's effects?

Scenario: I set the default device orientation to portrait. However, there are some Views that I want to allow for landscape mode.
Most of my views don't need to be in landscape. But there are some with orientation detection that allows a full-size linear graph to be displayed in landscape mode.
I want my application to behave as a Portrait-Centric for most of the time.
Question: How do I freeze the Portrait when I need to, but allow for Landscape when the situation warrants it?
You can manually allow, and most importantly in your case, disallow device orientation through UIInterfaceOrientation. Full description was already answered here: https://stackoverflow.com/a/40859280/13296047

Get "locked orientation", also known as "view orientation"

I have locked the orientation via XCode to be either landscape-left and landscape-right, but using UIDevice.current.orientation is giving the orientation as if it was not locked. Like when I am physically (in real life) in portrait, but my view is locked in landscape-left, I want to still get landscape-left, is this possible?
I can of course get the non-specific orientation by testing if width > height. But i needed the specific orientation of either landscape-left or -right.
Instead of asking the device for its orientation, ask the app for its orientation, by asking for UIApplication.shared.statusBarOrientation.

Device Orientation iOS

I want to have my app always in portrait mode facing up. That means that if the device it tipped to passed perpendicular to the floor and is starting to face the floor, it will readjust so it functions like it is in portrait mode facing upward. The same with if the device starts to be portrait upside-down, it will be portrait facing up (tilted upward. I have placed this in my apps delegate
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
under the -(BOOL) application did finishLaunching etc. but I need to know what I need to put into the delegate so throughout the app the above is always true.
Anyone help.
You specifying all required orientations in your Info.plist file as Array with a key UISupportedInterfaceOrientations Limit the list of supported orientation to the orientation that you want. beginGeneratingDeviceOrientationNotifications is very specific method that required for a unique use-cases but not for general orientation handling. Here is some of examples where beginGeneratingDeviceOrientationNotifications could be useful, but it is definitely not your case - How to handle autorotation in AVCaptureVideoPreviewLayer?
You can set this in your project's deployment info in Xcode.
I think you also need to implement shouldAutorotate and supportedInterfaceOrientations in your UIViewControllers. This Apple reference doc should help: UIViewController Class Reference.
Also, here's a similar question and answer.

Starting iPad app in current landscape orientation

My ipad app only runs in landscape orientation. But when I test on an actual device (not the simulator) it always seem to start in one particular landscape orientation, then turn 180 degrees to match the current physical landscape orientation. So, it seems to start in LandscapeLeft(I think) then rotate 180 if I have it in LandscapeRight. There's nothing in Info.plist to set the initial orientation.
Can anyone suggest a way to detect current orientation before view loads and set it to correct landscape view before showing?
Thanks
Fitto
There is the UIInterfaceOrientation~iPad key which sets the initial interface orientation on startup.
There is also the UISupportedInterfaceOrientations key which informs the app which orientations are supported.
There is no way, however, to make the app start in the current orientation of the iPad.
Have you looked into these questions?
Get current orientation of iPad?
iPad launch orientation
Also, technically, the iPad should just do it. Make sure you have supported orientations set properly, as I'm sure it checks those to see where it should start.

iPad orienatation need :application rejected

I want to know that does apple approves application having any two of the orientation?
Like Landscape Left and Landscape right ,
Or Portrait mode and Portrait mode Upside down,
My application is having functionality of Drawing and to shows number of images .
Is it only required or I need to use all orientation for the application.
I had put only one orientation and application was rejected but I came to know from some sources that apple allows any two of the orientation , Is it true?
Thanks in advance.
Judging from the thread in the comments below I think you need to support at least 2 rotations. So Both portraits or both landscape or all 4 rotations.
(in my opinion, if your app is landscape you must support both rotations, if it's portrait Apple may be more accepting if you don't support portrait upside down)
Apple require that for iPad you must support all orientations. That's just fact, and there is no possibility to do anything with that.

Resources