Ask permission to unlock screen orientation in Swift - ios

I'm working on a photo capturing application.
My app only supports portrait mode and I have to rotate landscape images to rotate them for the portrait mode. For example I want to rotate the photo 90 degrees right if it was captured in landscapeRight.
But if user device is in "Lock screen orientation" mode, I can't get the correct device orientation value with UIDevice.current.orientation if user is trying to take a landscape positioned photo. It always returns "portrait" value of course due to the "lock screen oritentation".
I want to ask permission to user for unlocking screen orientation with like "This application wants to unlock your screen orientation" message. Is it possible to add my info.plist to add a permission request for unlocking screen orientation? And if yes, which permission do I have to add in my info.plist?
Thanks in advance.

I concur you can't change the orientation properties. All those properties (in your project page) do is to enable state variables and notifications from which you can animate the orientation of your UI. So perhaps a hacky solution would be to look at using gyroscope APIs, and to make a small algorithm based on that to detect device rotation. It would essentially come down to building logic similar to a Leveling App. https://developer.apple.com/documentation/coremotion/cmmotionmanager

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.

iOS Is it possible to change orientation of device when default device rotation is off?

Today I was surprised by a feature of camera in apple when I rotate device to landscape mode icons were also rotated in landscape mode, Although the Automatic rotation was off for my device, How it can happen?
If default device rotation is off then how can camera app know that device orientation is changed?
I double checked my phones settings of Auto-Rotation and they were off.
The device-orientation setting is ignored for the camera. This was done so that people can keep orientation-lock on and take landscape photos at the same time, without having to constantly change the setting.

iPad Take Photo changes orientation

I am developing a PhoneGap app for iPads with a landscape-only orientation and I have run into a problem that I can't seem to figure out. In the app is a feature that allows you to take a photo of a customer. If you take and crop the photo in landscape mode, it looks like it tries to change the orientation of the app to portrait (I get a black bar on the right side). However, if you take and crop the photo in portrait mode, the app stays in landscape. You can even take the photo in landscape and crop it in portrait and the app will maintain its landscape orientation. I now assume that the problem lies in whatever happens when I click "Use" in the crop screen (Move and Scale screen). Does anyone know what could be causing this or how to fix it? Thanks.

UIDeviceOrientationDidChangeNotification event not firing when user disable screen auto-rotation

I can receive UIDeviceOrientationDidChangeNotification event, if auto-rotation is set.
But when screen auto rotation is disable, orientation notification doesn't work any more.
The effect I want to achieve is as iPhone Camera and Camera+: whatever the user lock or not lock the screen rotation, application can correspond to the rotation change immediately and correctly.
Does anyone has any idea why notification not sent when user lock the screen rotation?
How could I correspond to the device orientation change even if auto-rotation is disabled?
I also want to get the effect of the Camera app, where the app detects the orientation of the device even if the user has set Portrait Orientation Locked. UIDeviceOrientationDidChangeNotification is not posted when the user has portrait orientation locked. I believe the only way to determine the orientation of the device when the user has locked the orientation to portrait is to manually work out the orientation using UIAccelerometer.
The list of questions & answers below are all related to this issue. I found them when I was searching for an answer, and you might find them helpful too.
Related questions:
How to detect Camera Overlay view rotation
How to do Orientation Detection even the device has locked orientation
Detect iOS device orientation lock
Detect iPhone screen orientation
Callback method on auto rotation, iOS and iPad

Resources